[ { "hash": "7849a6df2b49453bb04d853f0820922d7e49fed5", "msg": "Refactored get_svn_revision from generate_svn_version_py.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-02T19:23:58+00:00", "author_timezone": 0, "committer_date": "2004-05-02T19:23:58+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "64bc6e30bbf6b685bfbaefad8f05f25ec262b2cb" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 4, "insertions": 11, "lines": 15, "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": "@@ -548,6 +548,16 @@ def generate_svn_version_py(extension, build_dir):\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n+ revision = get_svn_revision(local_path)\n+ f = open(target,'w')\n+ f.write('revision=%s\\n' % (revision))\n+ f.close()\n+ return target\n+\n+def get_svn_revision(path):\n+ \"\"\" Return path's SVN revision number.\n+ \"\"\"\n+ entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n@@ -555,10 +565,7 @@ def generate_svn_version_py(extension, build_dir):\n f.close()\n if m:\n revision = m.group('revision')\n- f = open(target,'w')\n- f.write('revision=%s\\n' % (revision))\n- f.close()\n- return target\n+ return revision\n \n if __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n", "added_lines": 11, "deleted_lines": 4, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = m.group('revision')\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = m.group('revision')\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 72, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 18, "complexity": 4, "token_count": 131, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 72, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "nloc": 414, "complexity": 130, "token_count": 3001, "diff_parsed": { "added": [ " revision = get_svn_revision(local_path)", " f = open(target,'w')", " f.write('revision=%s\\n' % (revision))", " f.close()", " return target", "", "def get_svn_revision(path):", " \"\"\" Return path's SVN revision number.", " \"\"\"", " entries = os.path.join(path,'.svn','entries')", " return revision" ], "deleted": [ " f = open(target,'w')", " f.write('revision=%s\\n' % (revision))", " f.close()", " return target" ] } } ] }, { "hash": "6e1a504e44931160134310d3b46a4cb3b164ed59", "msg": "svn revision number must be int.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-02T19:28:42+00:00", "author_timezone": 0, "committer_date": "2004-05-02T19:28:42+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7849a6df2b49453bb04d853f0820922d7e49fed5" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/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/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -565,7 +565,7 @@ def get_svn_revision(path):\n f.close()\n if m:\n revision = m.group('revision')\n- return revision\n+ return int(revision)\n \n if __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = m.group('revision')\n return int(revision)\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = m.group('revision')\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 72, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "nloc": 414, "complexity": 130, "token_count": 3004, "diff_parsed": { "added": [ " return int(revision)" ], "deleted": [ " return revision" ] } } ] }, { "hash": "4350ab085c7bf9377540affd8a03caf3bdf436ec", "msg": "Disabled hard-linking when creating source archives to avoid modifying (changing eol-style) files in source tree. When enabled, modifications will be undone after an archive is created; however, dos->unix->dos is not always identity mapping (e.g. try on chaco/wxplt.py) and that's the reason for always making a copy.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-03T07:32:19+00:00", "author_timezone": 0, "committer_date": "2004-05-03T07:32:19+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6e1a504e44931160134310d3b46a4cb3b164ed59" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 19, "insertions": 33, "lines": 52, "files": 3, "dmm_unit_size": 0.7857142857142857, "dmm_unit_complexity": 0.9285714285714286, "dmm_unit_interfacing": 0.5714285714285714, "modified_files": [ { "old_path": "scipy_distutils/command/sdist.py", "new_path": "scipy_distutils/command/sdist.py", "filename": "sdist.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -38,13 +38,16 @@ def make_release_tree (self, base_dir, files):\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n+\n+ \n \n- if hasattr(os, 'link'): # can make hard links on this system\n+ if 0 and hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n+ self._use_hard_link = not not link\n \n if not files:\n log.warn(\"no files to distribute -- empty manifest?\")\n@@ -52,7 +55,7 @@ def make_release_tree (self, base_dir, files):\n log.info(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n- file_pairs = zip(files,dest_files) \n+ file_pairs = zip(files,dest_files)\n for file,dest in file_pairs:\n if not os.path.isfile(file):\n log.warn(\"'%s' not a regular file -- skipping\", file)\n@@ -90,11 +93,13 @@ def make_distribution (self):\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n- for fmt in self.formats: \n- self.convert_line_endings(base_dir,fmt)\n+ for fmt in self.formats:\n+ modified_files,restore_func = self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n- \n+ if self._use_hard_link:\n+ map(restore_func,modified_files)\n+\n self.archive_files = archive_files\n \n if not self.keep_temp:\n@@ -107,10 +112,11 @@ def convert_line_endings(self,base_dir,fmt):\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n- line_endings.dos2unix_dir(base_dir)\n+ return line_endings.dos2unix_dir(base_dir),line_endings.unix2dos\n elif fmt == 'zip':\n- line_endings.unix2dos_dir(base_dir)\n- \n+ return line_endings.unix2dos_dir(base_dir),line_endings.dos2unix\n+ return [],lambda a:None\n+\n def remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n", "added_lines": 14, "deleted_lines": 8, "source_code": "\nimport os\nimport sys\n\nfrom distutils.command.sdist import *\nfrom distutils.command.sdist import sdist as old_sdist\nfrom scipy_distutils import log\nfrom scipy_distutils import line_endings\n\nclass sdist(old_sdist):\n def add_defaults (self):\n old_sdist.add_defaults(self)\n\n if self.distribution.has_data_files():\n self.filelist.extend(self.distribution.get_data_files())\n\n def make_release_tree (self, base_dir, files):\n \"\"\"Create the directory tree that will become the source\n distribution archive. All directories implied by the filenames in\n 'files' are created under 'base_dir', and then we hard link or copy\n (if hard linking is unavailable) those files into place.\n Essentially, this duplicates the developer's source tree, but in a\n directory named after the distribution, containing only the files\n to be distributed.\n \"\"\"\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n \n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n verbose=self.verbose, dry_run=self.dry_run)\n\n # And walk over the list of files, either making a hard link (if\n # os.link exists) to each one that doesn't already exist in its\n # corresponding location under 'base_dir', or copying each file\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n\n \n \n if 0 and hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n self._use_hard_link = not not link\n\n if not files:\n log.warn(\"no files to distribute -- empty manifest?\")\n else:\n log.info(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n file_pairs = zip(files,dest_files)\n for file,dest in file_pairs:\n if not os.path.isfile(file):\n log.warn(\"'%s' not a regular file -- skipping\", file)\n else:\n #ej: here is the only change -- made to handle\n # absolute paths to files as well as relative\n #par,file_name = os.path.split(file)\n #dest = os.path.join(base_dir, file_name)\n # end of changes\n \n # old code\n #dest = os.path.join(base_dir, file)\n #end old code\n self.copy_file(file, dest, link=link)\n\n self.distribution.metadata.write_pkg_info(base_dir)\n #raise ValueError\n # make_release_tree ()\n\n def make_distribution (self):\n \"\"\" Overridden to force a build of zip files to have Windows line \n endings and tar balls to have Unix line endings.\n \n Create the source distribution(s). First, we create the release\n tree with 'make_release_tree()'; then, we create all required\n archive files (according to 'self.formats') from the release tree.\n Finally, we clean up by blowing away the release tree (unless\n 'self.keep_temp' is true). The list of archive files created is\n stored so it can be retrieved later by 'get_archive_files()'.\n \"\"\"\n # Don't warn about missing meta-data here -- should be (and is!)\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats:\n modified_files,restore_func = self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n if self._use_hard_link:\n map(restore_func,modified_files)\n\n self.archive_files = archive_files\n\n if not self.keep_temp:\n dir_util.remove_tree(base_dir, self.verbose, self.dry_run)\n\n def convert_line_endings(self,base_dir,fmt):\n \"\"\" Convert all text files in a tree to have correct line endings.\n \n gztar --> \\n (Unix style)\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n return line_endings.dos2unix_dir(base_dir),line_endings.unix2dos\n elif fmt == 'zip':\n return line_endings.unix2dos_dir(base_dir),line_endings.dos2unix\n return [],lambda a:None\n\ndef remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n list without a parent directory are not affected.\n \"\"\"\n rel_files = filter(lambda x: not os.path.dirname(x),files)\n abs_files = filter(os.path.dirname,files)\n base = find_common_base(abs_files)\n # will leave files with local path unaffected\n # and maintains original file order\n results = [file[len(base):] for file in files]\n return results\n\ndef find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n return ''\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n while(keep_looking and d):\n keep_looking = 0\n for file in files:\n if string.find('start'+file,'start'+d) == -1:\n keep_looking = 1\n break\n if keep_looking:\n d,f = os.path.split(d)\n else:\n result = d\n \n if d: \n d = os.path.join(d,'')\n return d \n", "source_code_before": "\nimport os\nimport sys\n\nfrom distutils.command.sdist import *\nfrom distutils.command.sdist import sdist as old_sdist\nfrom scipy_distutils import log\nfrom scipy_distutils import line_endings\n\nclass sdist(old_sdist):\n def add_defaults (self):\n old_sdist.add_defaults(self)\n\n if self.distribution.has_data_files():\n self.filelist.extend(self.distribution.get_data_files())\n\n def make_release_tree (self, base_dir, files):\n \"\"\"Create the directory tree that will become the source\n distribution archive. All directories implied by the filenames in\n 'files' are created under 'base_dir', and then we hard link or copy\n (if hard linking is unavailable) those files into place.\n Essentially, this duplicates the developer's source tree, but in a\n directory named after the distribution, containing only the files\n to be distributed.\n \"\"\"\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n \n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n verbose=self.verbose, dry_run=self.dry_run)\n\n # And walk over the list of files, either making a hard link (if\n # os.link exists) to each one that doesn't already exist in its\n # corresponding location under 'base_dir', or copying each file\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n \n if hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n\n if not files:\n log.warn(\"no files to distribute -- empty manifest?\")\n else:\n log.info(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n file_pairs = zip(files,dest_files) \n for file,dest in file_pairs:\n if not os.path.isfile(file):\n log.warn(\"'%s' not a regular file -- skipping\", file)\n else:\n #ej: here is the only change -- made to handle\n # absolute paths to files as well as relative\n #par,file_name = os.path.split(file)\n #dest = os.path.join(base_dir, file_name)\n # end of changes\n \n # old code\n #dest = os.path.join(base_dir, file)\n #end old code\n self.copy_file(file, dest, link=link)\n\n self.distribution.metadata.write_pkg_info(base_dir)\n #raise ValueError\n # make_release_tree ()\n\n def make_distribution (self):\n \"\"\" Overridden to force a build of zip files to have Windows line \n endings and tar balls to have Unix line endings.\n \n Create the source distribution(s). First, we create the release\n tree with 'make_release_tree()'; then, we create all required\n archive files (according to 'self.formats') from the release tree.\n Finally, we clean up by blowing away the release tree (unless\n 'self.keep_temp' is true). The list of archive files created is\n stored so it can be retrieved later by 'get_archive_files()'.\n \"\"\"\n # Don't warn about missing meta-data here -- should be (and is!)\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats: \n self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n \n self.archive_files = archive_files\n\n if not self.keep_temp:\n dir_util.remove_tree(base_dir, self.verbose, self.dry_run)\n\n def convert_line_endings(self,base_dir,fmt):\n \"\"\" Convert all text files in a tree to have correct line endings.\n \n gztar --> \\n (Unix style)\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n line_endings.dos2unix_dir(base_dir)\n elif fmt == 'zip':\n line_endings.unix2dos_dir(base_dir)\n \ndef remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n list without a parent directory are not affected.\n \"\"\"\n rel_files = filter(lambda x: not os.path.dirname(x),files)\n abs_files = filter(os.path.dirname,files)\n base = find_common_base(abs_files)\n # will leave files with local path unaffected\n # and maintains original file order\n results = [file[len(base):] for file in files]\n return results\n\ndef find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n return ''\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n while(keep_looking and d):\n keep_looking = 0\n for file in files:\n if string.find('start'+file,'start'+d) == -1:\n keep_looking = 1\n break\n if keep_looking:\n d,f = os.path.split(d)\n else:\n result = d\n \n if d: \n d = os.path.join(d,'')\n return d \n", "methods": [ { "name": "add_defaults", "long_name": "add_defaults( self )", "filename": "sdist.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 11, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 24, "complexity": 7, "token_count": 171, "parameters": [ "self", "base_dir", "files" ], "start_line": 17, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 1 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 15, "complexity": 4, "token_count": 132, "parameters": [ "self" ], "start_line": 78, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 6, "complexity": 3, "token_count": 50, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 108, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "remove_common_base", "long_name": "remove_common_base( files )", "filename": "sdist.py", "nloc": 6, "complexity": 2, "token_count": 61, "parameters": [ "files" ], "start_line": 120, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 133, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "methods_before": [ { "name": "add_defaults", "long_name": "add_defaults( self )", "filename": "sdist.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "self" ], "start_line": 11, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 17, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 1 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 13, "complexity": 3, "token_count": 117, "parameters": [ "self" ], "start_line": 75, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 103, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "remove_common_base", "long_name": "remove_common_base( files )", "filename": "sdist.py", "nloc": 6, "complexity": 2, "token_count": 61, "parameters": [ "files" ], "start_line": 114, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 127, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 15, "complexity": 4, "token_count": 132, "parameters": [ "self" ], "start_line": 78, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 24, "complexity": 7, "token_count": 171, "parameters": [ "self", "base_dir", "files" ], "start_line": 17, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 6, "complexity": 3, "token_count": 50, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 108, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "nloc": 81, "complexity": 26, "token_count": 596, "diff_parsed": { "added": [ "", "", " if 0 and hasattr(os, 'link'): # can make hard links on this system", " self._use_hard_link = not not link", " file_pairs = zip(files,dest_files)", " for fmt in self.formats:", " modified_files,restore_func = self.convert_line_endings(base_dir,fmt)", " if self._use_hard_link:", " map(restore_func,modified_files)", "", " return line_endings.dos2unix_dir(base_dir),line_endings.unix2dos", " return line_endings.unix2dos_dir(base_dir),line_endings.dos2unix", " return [],lambda a:None", "" ], "deleted": [ " if hasattr(os, 'link'): # can make hard links on this system", " file_pairs = zip(files,dest_files)", " for fmt in self.formats:", " self.convert_line_endings(base_dir,fmt)", "", " line_endings.dos2unix_dir(base_dir)", " line_endings.unix2dos_dir(base_dir)", "" ] } }, { "old_path": "scipy_distutils/line_endings.py", "new_path": "scipy_distutils/line_endings.py", "filename": "line_endings.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -20,17 +20,21 @@ def dos2unix(file):\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n+ return file\n else:\n print file, 'ok' \n \n-def dos2unix_one_dir(args,dir_name,file_names):\n+def dos2unix_one_dir(modified_files,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n- dos2unix(full_path)\n- \n-def dos2unix_dir(dir_name):\n- os.path.walk(dir_name,dos2unix_one_dir,[])\n+ file = dos2unix(full_path)\n+ if file is not None:\n+ modified_files.append(file)\n \n+def dos2unix_dir(dir_name):\n+ modified_files = []\n+ os.path.walk(dir_name,dos2unix_one_dir,modified_files)\n+ return modified_files\n #----------------------------------\n \n def unix2dos(file):\n@@ -43,7 +47,6 @@ def unix2dos(file):\n if '\\0' in data:\n print file, \"Binary!\"\n return\n- \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n newdata = re.sub(\"\\n\", \"\\r\\n\", newdata)\n if newdata != data:\n@@ -51,16 +54,21 @@ def unix2dos(file):\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n+ return file\n else:\n print file, 'ok' \n \n-def unix2dos_one_dir(args,dir_name,file_names):\n+def unix2dos_one_dir(modified_files,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n unix2dos(full_path)\n- \n+ if file is not None:\n+ modified_files.append(file)\n+\n def unix2dos_dir(dir_name):\n- os.path.walk(dir_name,unix2dos_one_dir,[])\n+ modified_files = []\n+ os.path.walk(dir_name,unix2dos_one_dir,modified_files)\n+ return modified_files\n \n if __name__ == \"__main__\":\n import sys\n", "added_lines": 17, "deleted_lines": 9, "source_code": "\"\"\" Functions for converting from DOS to UNIX line endings\n\"\"\"\n\nimport sys, re, os\n\ndef dos2unix(file):\n \"Replace CRLF with LF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n if newdata != data:\n print 'dos2unix:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n return file\n else:\n print file, 'ok' \n\ndef dos2unix_one_dir(modified_files,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n file = dos2unix(full_path)\n if file is not None:\n modified_files.append(file)\n\ndef dos2unix_dir(dir_name):\n modified_files = []\n os.path.walk(dir_name,dos2unix_one_dir,modified_files)\n return modified_files\n#----------------------------------\n\ndef unix2dos(file):\n \"Replace LF with CRLF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n newdata = re.sub(\"\\n\", \"\\r\\n\", newdata)\n if newdata != data:\n print 'unix2dos:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n return file\n else:\n print file, 'ok' \n\ndef unix2dos_one_dir(modified_files,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n unix2dos(full_path)\n if file is not None:\n modified_files.append(file)\n\ndef unix2dos_dir(dir_name):\n modified_files = []\n os.path.walk(dir_name,unix2dos_one_dir,modified_files)\n return modified_files\n \nif __name__ == \"__main__\":\n import sys\n dos2unix_dir(sys.argv[1])\n", "source_code_before": "\"\"\" Functions for converting from DOS to UNIX line endings\n\"\"\"\n\nimport sys, re, os\n\ndef dos2unix(file):\n \"Replace CRLF with LF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n if newdata != data:\n print 'dos2unix:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n else:\n print file, 'ok' \n\ndef dos2unix_one_dir(args,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n dos2unix(full_path)\n \ndef dos2unix_dir(dir_name):\n os.path.walk(dir_name,dos2unix_one_dir,[])\n\n#----------------------------------\n\ndef unix2dos(file):\n \"Replace LF with CRLF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n newdata = re.sub(\"\\n\", \"\\r\\n\", newdata)\n if newdata != data:\n print 'unix2dos:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n else:\n print file, 'ok' \n\ndef unix2dos_one_dir(args,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n unix2dos(full_path)\n \ndef unix2dos_dir(dir_name):\n os.path.walk(dir_name,unix2dos_one_dir,[])\n \nif __name__ == \"__main__\":\n import sys\n dos2unix_dir(sys.argv[1])\n", "methods": [ { "name": "dos2unix", "long_name": "dos2unix( file )", "filename": "line_endings.py", "nloc": 18, "complexity": 4, "token_count": 91, "parameters": [ "file" ], "start_line": 6, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "dos2unix_one_dir", "long_name": "dos2unix_one_dir( modified_files , dir_name , file_names )", "filename": "line_endings.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "modified_files", "dir_name", "file_names" ], "start_line": 27, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "dos2unix_dir", "long_name": "dos2unix_dir( dir_name )", "filename": "line_endings.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "dir_name" ], "start_line": 34, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unix2dos", "long_name": "unix2dos( file )", "filename": "line_endings.py", "nloc": 19, "complexity": 4, "token_count": 103, "parameters": [ "file" ], "start_line": 40, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unix2dos_one_dir", "long_name": "unix2dos_one_dir( modified_files , dir_name , file_names )", "filename": "line_endings.py", "nloc": 6, "complexity": 3, "token_count": 42, "parameters": [ "modified_files", "dir_name", "file_names" ], "start_line": 61, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "unix2dos_dir", "long_name": "unix2dos_dir( dir_name )", "filename": "line_endings.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "dir_name" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "methods_before": [ { "name": "dos2unix", "long_name": "dos2unix( file )", "filename": "line_endings.py", "nloc": 17, "complexity": 4, "token_count": 89, "parameters": [ "file" ], "start_line": 6, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "dos2unix_one_dir", "long_name": "dos2unix_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 26, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "dos2unix_dir", "long_name": "dos2unix_dir( dir_name )", "filename": "line_endings.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "dir_name" ], "start_line": 31, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "unix2dos", "long_name": "unix2dos( file )", "filename": "line_endings.py", "nloc": 18, "complexity": 4, "token_count": 101, "parameters": [ "file" ], "start_line": 36, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unix2dos_one_dir", "long_name": "unix2dos_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 57, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unix2dos_dir", "long_name": "unix2dos_dir( dir_name )", "filename": "line_endings.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "dir_name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "unix2dos_one_dir", "long_name": "unix2dos_one_dir( modified_files , dir_name , file_names )", "filename": "line_endings.py", "nloc": 6, "complexity": 3, "token_count": 42, "parameters": [ "modified_files", "dir_name", "file_names" ], "start_line": 61, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "dos2unix_one_dir", "long_name": "dos2unix_one_dir( modified_files , dir_name , file_names )", "filename": "line_endings.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "modified_files", "dir_name", "file_names" ], "start_line": 27, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "dos2unix_dir", "long_name": "dos2unix_dir( dir_name )", "filename": "line_endings.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "dir_name" ], "start_line": 34, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unix2dos_one_dir", "long_name": "unix2dos_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 57, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "dos2unix_one_dir", "long_name": "dos2unix_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 26, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "dos2unix", "long_name": "dos2unix( file )", "filename": "line_endings.py", "nloc": 18, "complexity": 4, "token_count": 91, "parameters": [ "file" ], "start_line": 6, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unix2dos_dir", "long_name": "unix2dos_dir( dir_name )", "filename": "line_endings.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "dir_name" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unix2dos", "long_name": "unix2dos( file )", "filename": "line_endings.py", "nloc": 19, "complexity": 4, "token_count": 103, "parameters": [ "file" ], "start_line": 40, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "nloc": 63, "complexity": 16, "token_count": 355, "diff_parsed": { "added": [ " return file", "def dos2unix_one_dir(modified_files,dir_name,file_names):", " file = dos2unix(full_path)", " if file is not None:", " modified_files.append(file)", "def dos2unix_dir(dir_name):", " modified_files = []", " os.path.walk(dir_name,dos2unix_one_dir,modified_files)", " return modified_files", " return file", "def unix2dos_one_dir(modified_files,dir_name,file_names):", " if file is not None:", " modified_files.append(file)", "", " modified_files = []", " os.path.walk(dir_name,unix2dos_one_dir,modified_files)", " return modified_files" ], "deleted": [ "def dos2unix_one_dir(args,dir_name,file_names):", " dos2unix(full_path)", "", "def dos2unix_dir(dir_name):", " os.path.walk(dir_name,dos2unix_one_dir,[])", "", "def unix2dos_one_dir(args,dir_name,file_names):", "", " os.path.walk(dir_name,unix2dos_one_dir,[])" ] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -564,8 +564,8 @@ def get_svn_revision(path):\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n- revision = m.group('revision')\n- return int(revision)\n+ revision = int(m.group('revision'))\n+ return revision\n \n if __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = m.group('revision')\n return int(revision)\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "nloc": 414, "complexity": 130, "token_count": 3004, "diff_parsed": { "added": [ " revision = int(m.group('revision'))", " return revision" ], "deleted": [ " revision = m.group('revision')", " return int(revision)" ] } } ] }, { "hash": "be1d0a5c4163b65d9717724c612e718c42721d93", "msg": "If extension has no sources then there will be no output. Fixes bdist_rpm command.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-03T10:15:49+00:00", "author_timezone": 0, "committer_date": "2004-05-03T10:15:49+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4350ab085c7bf9377540affd8a03caf3bdf436ec" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 0, "insertions": 12, "lines": 12, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_ext.py", "new_path": "scipy_distutils/command/build_ext.py", "filename": "build_ext.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -338,6 +338,18 @@ def visit_func(filenames,dirname,names):\n filenames.append(d)\n return filenames\n \n+ def get_outputs (self):\n+ self.check_extensions_list(self.extensions)\n+\n+ outputs = []\n+ for ext in self.extensions:\n+ if not ext.sources:\n+ continue\n+ fullname = self.get_ext_fullname(ext.name)\n+ outputs.append(os.path.join(self.build_lib,\n+ self.get_ext_filename(fullname)))\n+ return outputs\n+\n def is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n", "added_lines": 12, "deleted_lines": 0, "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n if not sources:\n return\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n if cxx_sources:\n # Needed to compile kiva.agg._agg extension.\n extra_args.append('/Zm1000')\n # this hack works around the msvc compiler attributes\n # problem, msvc uses its own convention :(\n c_sources += cxx_sources\n cxx_sources = []\n\n if sys.version[:3]>='2.3':\n kws = {'depends':ext.depends}\n else:\n kws = {}\n\n c_objects = []\n if c_sources:\n log.info(\"compling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n include_dirs = ext.include_dirs[:]\n module_dirs = ext.module_dirs[:]\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n \n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n \n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90']\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries(): \n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries,\n library_dirs=ext.library_dirs + c_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n sources = filter(lambda s:type(s) is StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\n def get_outputs (self):\n self.check_extensions_list(self.extensions)\n\n outputs = []\n for ext in self.extensions:\n if not ext.sources:\n continue\n fullname = self.get_ext_fullname(ext.name)\n outputs.append(os.path.join(self.build_lib,\n self.get_ext_filename(fullname)))\n return outputs\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return 0\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n", "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n if not sources:\n return\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n if cxx_sources:\n # Needed to compile kiva.agg._agg extension.\n extra_args.append('/Zm1000')\n # this hack works around the msvc compiler attributes\n # problem, msvc uses its own convention :(\n c_sources += cxx_sources\n cxx_sources = []\n\n if sys.version[:3]>='2.3':\n kws = {'depends':ext.depends}\n else:\n kws = {}\n\n c_objects = []\n if c_sources:\n log.info(\"compling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n include_dirs = ext.include_dirs[:]\n module_dirs = ext.module_dirs[:]\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n \n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n \n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90']\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries(): \n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries,\n library_dirs=ext.library_dirs + c_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n if name[-1] in \"~#\":\n continue\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n sources = filter(lambda s:type(s) is StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return 0\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n", "methods": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_ext.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 29, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_ext.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 34, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_ext.py", "nloc": 50, "complexity": 14, "token_count": 304, "parameters": [ "self" ], "start_line": 40, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources )", "filename": "build_ext.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "sources" ], "start_line": 108, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 169, "complexity": 46, "token_count": 1090, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 203, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "filenames", "dirname", "names" ], "start_line": 319, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 316, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_outputs", "long_name": "get_outputs( self )", "filename": "build_ext.py", "nloc": 10, "complexity": 3, "token_count": 65, "parameters": [ "self" ], "start_line": 341, "end_line": 351, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 353, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_ext.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 29, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_ext.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 34, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_ext.py", "nloc": 50, "complexity": 14, "token_count": 304, "parameters": [ "self" ], "start_line": 40, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources )", "filename": "build_ext.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "sources" ], "start_line": 108, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 169, "complexity": 46, "token_count": 1090, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 203, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "filenames", "dirname", "names" ], "start_line": 319, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 316, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 341, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_outputs", "long_name": "get_outputs( self )", "filename": "build_ext.py", "nloc": 10, "complexity": 3, "token_count": 65, "parameters": [ "self" ], "start_line": 341, "end_line": 351, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "nloc": 293, "complexity": 81, "token_count": 1886, "diff_parsed": { "added": [ " def get_outputs (self):", " self.check_extensions_list(self.extensions)", "", " outputs = []", " for ext in self.extensions:", " if not ext.sources:", " continue", " fullname = self.get_ext_fullname(ext.name)", " outputs.append(os.path.join(self.build_lib,", " self.get_ext_filename(fullname)))", " return outputs", "" ], "deleted": [] } } ] }, { "hash": "f3e93c709c312fe3a8914acdd31aeb659fecdec2", "msg": "Don't scan build directory for modules.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-03T10:57:37+00:00", "author_timezone": 0, "committer_date": "2004-05-03T10:57:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "be1d0a5c4163b65d9717724c612e718c42721d93" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 2, "insertions": 3, "lines": 5, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -391,8 +391,9 @@ def compiler_to_string(compiler):\n \n def _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n- if '.svn' in names:\n- del names[names.index('.svn')]\n+ for bad in ['.svn','build']:\n+ if bad in names:\n+ del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n", "added_lines": 3, "deleted_lines": 2, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n if '.svn' in names:\n del names[names.index('.svn')]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 403, "end_line": 493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 495, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 558, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 9, "complexity": 5, "token_count": 95, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 402, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 494, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 532, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 557, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 } ], "nloc": 415, "complexity": 131, "token_count": 3013, "diff_parsed": { "added": [ " for bad in ['.svn','build']:", " if bad in names:", " del names[names.index(bad)]" ], "deleted": [ " if '.svn' in names:", " del names[names.index('.svn')]" ] } } ] }, { "hash": "07b23a559d634f6740470aec995bc5bf03f53b7b", "msg": "Backport to Python <=2.2: cannot use slice object for strings.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-03T16:30:05+00:00", "author_timezone": 0, "committer_date": "2004-05-03T16:30:05+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f3e93c709c312fe3a8914acdd31aeb659fecdec2" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 2, "insertions": 1, "lines": 3, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/from_template.py", "new_path": "scipy_distutils/from_template.py", "filename": "from_template.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -165,8 +165,7 @@ def process_str(allstr):\n oldend = 0\n for sub in struct:\n writestr += newstr[oldend:sub[0]]\n- obj = slice(sub[0],sub[1])\n- expanded = expand_sub(newstr[obj],get_line_header(newstr,sub[0]))\n+ expanded = expand_sub(newstr[sub[0]:sub[1]],get_line_header(newstr,sub[0]))\n writestr += expanded\n oldend = sub[1]\n \n", "added_lines": 1, "deleted_lines": 2, "source_code": "#!/usr/bin/python\n\n# takes templated file .xxx.src and produces .xxx file where .xxx is .pyf .f90 or .f\n# using the following template rules\n\n# <...> is the template All blocks in a source file with names that\n# contain '<..>' will be replicated according to the\n# rules in '<..>'.\n\n# The number of comma-separeted words in '<..>' will determine the number of\n# replicates.\n \n# '<..>' may have two different forms, named and short. For example,\n\n#named:\n# where anywhere inside a block '

' will be replaced with\n# 'd', 's', 'z', and 'c' for each replicate of the block.\n\n# <_c> is already defined: <_c=s,d,c,z>\n# <_t> is already defined: <_t=real,double precision,complex,double complex>\n\n#short:\n# , a short form of the named, useful when no

appears inside \n# a block.\n\n# Note that all <..> forms in a block must have the same number of\n# comma-separated entries. \n\n__all__ = ['process_str']\n\nimport string,os,sys\nif sys.version[:3]>='2.3':\n import re\nelse:\n import pre as re\n False = 0\n True = 1\n\ncomment_block_exp = re.compile(r'/\\*(?:\\s|.)*?\\*/')\nsubroutine_exp = re.compile(r'subroutine (?:\\s|.)*?end subroutine.*')\nfunction_exp = re.compile(r'function (?:\\s|.)*?end function.*')\nreg = re.compile(r\"\\ssubroutine\\s(.+)\\(.*\\)\")\n\ndef parse_structure(astr):\n spanlist = []\n for typ in [subroutine_exp, function_exp]:\n ind = 0\n while 1:\n a = typ.search(astr[ind:])\n if a is None:\n break\n tup = a.span()\n tup = (ind+tup[0],ind+tup[1])\n spanlist.append(tup)\n ind = tup[1]\n\n spanlist.sort()\n return spanlist\n\n# return n copies of substr with template replacement\n_special_names = {'_c':'s,d,c,z',\n '_t':'real,double precision,complex,double complex'\n }\ntemplate_re = re.compile(r\"<([\\w]*)>\")\nnamed_re = re.compile(r\"<([\\w]*)=([, \\w]*)>\")\nlist_re = re.compile(r\"<([\\w ]+(,\\s*[\\w]+)+)>\")\n\ndef conv(astr):\n b = astr.split(',')\n return ','.join([x.strip().lower() for x in b])\n\ndef unique_key(adict):\n # this obtains a unique key given a dictionary\n # currently it works by appending together n of the letters of the\n # current keys and increasing n until a unique key is found\n # -- not particularly quick\n allkeys = adict.keys()\n done = False\n n = 1\n while not done:\n newkey = \"\".join([x[:n] for x in allkeys])\n if newkey in allkeys:\n n += 1\n else:\n done = True\n return newkey\n\ndef listrepl(match):\n global _names\n thelist = conv(match.group(1))\n name = None\n for key in _names.keys(): # see if list is already in dictionary\n if _names[key] == thelist:\n name = key\n if name is None: # this list is not in the dictionary yet\n name = \"%s\" % unique_key(_names)\n _names[name] = thelist\n return \"<%s>\" % name\n\ndef namerepl(match):\n global _names, _thissub\n name = match.group(1)\n return _names[name][_thissub]\n\ndef expand_sub(substr,extra=''):\n global _names, _thissub\n # find all named replacements\n reps = named_re.findall(substr)\n _names = {}\n _names.update(_special_names)\n numsubs = None\n for rep in reps:\n name = rep[0].strip().lower()\n thelist,num = conv(rep[1])\n _names[name] = thelist\n\n substr = named_re.sub(r\"<\\1>\",substr) # get rid of definition templates\n substr = list_re.sub(listrepl, substr) # convert all lists to named templates\n # newnames are constructed as needed\n\n # make lists out of string entries in name dictionary\n for name in _names.keys():\n entry = _names[name]\n entrylist = entry.split(',')\n _names[name] = entrylist\n num = len(entrylist)\n if numsubs is None:\n numsubs = num\n elif (numsubs != num):\n raise ValueError, \"Mismatch in number to replace\"\n\n # now replace all keys for each of the lists\n mystr = ''\n for k in range(numsubs):\n _thissub = k\n mystr += template_re.sub(namerepl, substr)\n mystr += \"\\n\\n\" + extra\n return mystr\n\n_head = \\\n\"\"\"C This file was autogenerated from a template DO NOT EDIT!!!!\nC Changes should be made to the original source (.src) file\nC\n\n\"\"\"\n\ndef get_line_header(str,beg):\n extra = []\n ind = beg-1\n char = str[ind]\n while (ind > 0) and (char != '\\n'):\n extra.insert(0,char)\n ind = ind - 1\n char = str[ind]\n return ''.join(extra)\n \ndef process_str(allstr):\n newstr = allstr.lower()\n writestr = _head\n\n struct = parse_structure(newstr)\n # return a (sorted) list of tuples for each function or subroutine\n # each tuple is the start and end of a subroutine or function to be expanded\n \n oldend = 0\n for sub in struct:\n writestr += newstr[oldend:sub[0]]\n expanded = expand_sub(newstr[sub[0]:sub[1]],get_line_header(newstr,sub[0]))\n writestr += expanded\n oldend = sub[1]\n\n writestr += newstr[oldend:]\n return writestr\n\n\nif __name__ == \"__main__\":\n\n try:\n file = sys.argv[1]\n except IndexError:\n fid = sys.stdin\n outfile = sys.stdout\n else:\n fid = open(file,'r')\n (base, ext) = os.path.splitext(file)\n newname = base\n outfile = open(newname,'w')\n\n allstr = fid.read()\n writestr = process_str(allstr)\n outfile.write(writestr)\n", "source_code_before": "#!/usr/bin/python\n\n# takes templated file .xxx.src and produces .xxx file where .xxx is .pyf .f90 or .f\n# using the following template rules\n\n# <...> is the template All blocks in a source file with names that\n# contain '<..>' will be replicated according to the\n# rules in '<..>'.\n\n# The number of comma-separeted words in '<..>' will determine the number of\n# replicates.\n \n# '<..>' may have two different forms, named and short. For example,\n\n#named:\n# where anywhere inside a block '

' will be replaced with\n# 'd', 's', 'z', and 'c' for each replicate of the block.\n\n# <_c> is already defined: <_c=s,d,c,z>\n# <_t> is already defined: <_t=real,double precision,complex,double complex>\n\n#short:\n# , a short form of the named, useful when no

appears inside \n# a block.\n\n# Note that all <..> forms in a block must have the same number of\n# comma-separated entries. \n\n__all__ = ['process_str']\n\nimport string,os,sys\nif sys.version[:3]>='2.3':\n import re\nelse:\n import pre as re\n False = 0\n True = 1\n\ncomment_block_exp = re.compile(r'/\\*(?:\\s|.)*?\\*/')\nsubroutine_exp = re.compile(r'subroutine (?:\\s|.)*?end subroutine.*')\nfunction_exp = re.compile(r'function (?:\\s|.)*?end function.*')\nreg = re.compile(r\"\\ssubroutine\\s(.+)\\(.*\\)\")\n\ndef parse_structure(astr):\n spanlist = []\n for typ in [subroutine_exp, function_exp]:\n ind = 0\n while 1:\n a = typ.search(astr[ind:])\n if a is None:\n break\n tup = a.span()\n tup = (ind+tup[0],ind+tup[1])\n spanlist.append(tup)\n ind = tup[1]\n\n spanlist.sort()\n return spanlist\n\n# return n copies of substr with template replacement\n_special_names = {'_c':'s,d,c,z',\n '_t':'real,double precision,complex,double complex'\n }\ntemplate_re = re.compile(r\"<([\\w]*)>\")\nnamed_re = re.compile(r\"<([\\w]*)=([, \\w]*)>\")\nlist_re = re.compile(r\"<([\\w ]+(,\\s*[\\w]+)+)>\")\n\ndef conv(astr):\n b = astr.split(',')\n return ','.join([x.strip().lower() for x in b])\n\ndef unique_key(adict):\n # this obtains a unique key given a dictionary\n # currently it works by appending together n of the letters of the\n # current keys and increasing n until a unique key is found\n # -- not particularly quick\n allkeys = adict.keys()\n done = False\n n = 1\n while not done:\n newkey = \"\".join([x[:n] for x in allkeys])\n if newkey in allkeys:\n n += 1\n else:\n done = True\n return newkey\n\ndef listrepl(match):\n global _names\n thelist = conv(match.group(1))\n name = None\n for key in _names.keys(): # see if list is already in dictionary\n if _names[key] == thelist:\n name = key\n if name is None: # this list is not in the dictionary yet\n name = \"%s\" % unique_key(_names)\n _names[name] = thelist\n return \"<%s>\" % name\n\ndef namerepl(match):\n global _names, _thissub\n name = match.group(1)\n return _names[name][_thissub]\n\ndef expand_sub(substr,extra=''):\n global _names, _thissub\n # find all named replacements\n reps = named_re.findall(substr)\n _names = {}\n _names.update(_special_names)\n numsubs = None\n for rep in reps:\n name = rep[0].strip().lower()\n thelist,num = conv(rep[1])\n _names[name] = thelist\n\n substr = named_re.sub(r\"<\\1>\",substr) # get rid of definition templates\n substr = list_re.sub(listrepl, substr) # convert all lists to named templates\n # newnames are constructed as needed\n\n # make lists out of string entries in name dictionary\n for name in _names.keys():\n entry = _names[name]\n entrylist = entry.split(',')\n _names[name] = entrylist\n num = len(entrylist)\n if numsubs is None:\n numsubs = num\n elif (numsubs != num):\n raise ValueError, \"Mismatch in number to replace\"\n\n # now replace all keys for each of the lists\n mystr = ''\n for k in range(numsubs):\n _thissub = k\n mystr += template_re.sub(namerepl, substr)\n mystr += \"\\n\\n\" + extra\n return mystr\n\n_head = \\\n\"\"\"C This file was autogenerated from a template DO NOT EDIT!!!!\nC Changes should be made to the original source (.src) file\nC\n\n\"\"\"\n\ndef get_line_header(str,beg):\n extra = []\n ind = beg-1\n char = str[ind]\n while (ind > 0) and (char != '\\n'):\n extra.insert(0,char)\n ind = ind - 1\n char = str[ind]\n return ''.join(extra)\n \ndef process_str(allstr):\n newstr = allstr.lower()\n writestr = _head\n\n struct = parse_structure(newstr)\n # return a (sorted) list of tuples for each function or subroutine\n # each tuple is the start and end of a subroutine or function to be expanded\n \n oldend = 0\n for sub in struct:\n writestr += newstr[oldend:sub[0]]\n obj = slice(sub[0],sub[1])\n expanded = expand_sub(newstr[obj],get_line_header(newstr,sub[0]))\n writestr += expanded\n oldend = sub[1]\n\n writestr += newstr[oldend:]\n return writestr\n\n\nif __name__ == \"__main__\":\n\n try:\n file = sys.argv[1]\n except IndexError:\n fid = sys.stdin\n outfile = sys.stdout\n else:\n fid = open(file,'r')\n (base, ext) = os.path.splitext(file)\n newname = base\n outfile = open(newname,'w')\n\n allstr = fid.read()\n writestr = process_str(allstr)\n outfile.write(writestr)\n", "methods": [ { "name": "parse_structure", "long_name": "parse_structure( astr )", "filename": "from_template.py", "nloc": 14, "complexity": 4, "token_count": 85, "parameters": [ "astr" ], "start_line": 44, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "conv", "long_name": "conv( astr )", "filename": "from_template.py", "nloc": 3, "complexity": 2, "token_count": 34, "parameters": [ "astr" ], "start_line": 68, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "unique_key", "long_name": "unique_key( adict )", "filename": "from_template.py", "nloc": 11, "complexity": 4, "token_count": 55, "parameters": [ "adict" ], "start_line": 72, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "listrepl", "long_name": "listrepl( match )", "filename": "from_template.py", "nloc": 11, "complexity": 4, "token_count": 64, "parameters": [ "match" ], "start_line": 88, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "namerepl", "long_name": "namerepl( match )", "filename": "from_template.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "match" ], "start_line": 100, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "expand_sub", "long_name": "expand_sub( substr , extra = '' )", "filename": "from_template.py", "nloc": 27, "complexity": 6, "token_count": 176, "parameters": [ "substr", "extra" ], "start_line": 105, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "get_line_header", "long_name": "get_line_header( str , beg )", "filename": "from_template.py", "nloc": 9, "complexity": 3, "token_count": 61, "parameters": [ "str", "beg" ], "start_line": 147, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "process_str", "long_name": "process_str( allstr )", "filename": "from_template.py", "nloc": 12, "complexity": 2, "token_count": 85, "parameters": [ "allstr" ], "start_line": 157, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 } ], "methods_before": [ { "name": "parse_structure", "long_name": "parse_structure( astr )", "filename": "from_template.py", "nloc": 14, "complexity": 4, "token_count": 85, "parameters": [ "astr" ], "start_line": 44, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "conv", "long_name": "conv( astr )", "filename": "from_template.py", "nloc": 3, "complexity": 2, "token_count": 34, "parameters": [ "astr" ], "start_line": 68, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "unique_key", "long_name": "unique_key( adict )", "filename": "from_template.py", "nloc": 11, "complexity": 4, "token_count": 55, "parameters": [ "adict" ], "start_line": 72, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "listrepl", "long_name": "listrepl( match )", "filename": "from_template.py", "nloc": 11, "complexity": 4, "token_count": 64, "parameters": [ "match" ], "start_line": 88, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "namerepl", "long_name": "namerepl( match )", "filename": "from_template.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "match" ], "start_line": 100, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "expand_sub", "long_name": "expand_sub( substr , extra = '' )", "filename": "from_template.py", "nloc": 27, "complexity": 6, "token_count": 176, "parameters": [ "substr", "extra" ], "start_line": 105, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "get_line_header", "long_name": "get_line_header( str , beg )", "filename": "from_template.py", "nloc": 9, "complexity": 3, "token_count": 61, "parameters": [ "str", "beg" ], "start_line": 147, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "process_str", "long_name": "process_str( allstr )", "filename": "from_template.py", "nloc": 13, "complexity": 2, "token_count": 91, "parameters": [ "allstr" ], "start_line": 157, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "process_str", "long_name": "process_str( allstr )", "filename": "from_template.py", "nloc": 12, "complexity": 2, "token_count": 85, "parameters": [ "allstr" ], "start_line": 157, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 } ], "nloc": 129, "complexity": 26, "token_count": 789, "diff_parsed": { "added": [ " expanded = expand_sub(newstr[sub[0]:sub[1]],get_line_header(newstr,sub[0]))" ], "deleted": [ " obj = slice(sub[0],sub[1])", " expanded = expand_sub(newstr[obj],get_line_header(newstr,sub[0]))" ] } } ] }, { "hash": "6f911baa014ebdbcc52916fecfdb5cc8fb8493ec", "msg": "Impl. ppimport.realize. Fixes help(module.attribute) bug.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-05T19:30:39+00:00", "author_timezone": 0, "committer_date": "2004-05-05T19:30:39+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "07b23a559d634f6740470aec995bc5bf03f53b7b" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 13, "insertions": 33, "lines": 46, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.18181818181818182, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -8,7 +8,7 @@\n $Revision$\n $Date$\n \"\"\"\n-__all__ = ['ppimport','ppimport_attr']\n+__all__ = ['ppimport','ppimport_attr','realize']\n \n import os\n import sys\n@@ -289,6 +289,36 @@ def __repr__(self):\n \n __str__ = __repr__\n \n+def realize(a):\n+ \"\"\" Return realized object a.\n+\n+ a can be module name, postponed module, postponed modules\n+ attribute, string representing module attribute, or any\n+ Python object.\n+ \"\"\"\n+ if type(a) is type(''):\n+ ns = a.split('.')\n+ a = ppimport(ns[0])\n+ b = [ns[0]]\n+ del ns[0]\n+ while ns:\n+ if hasattr(a,'_ppimport_importer') or \\\n+ hasattr(a,'_ppimport_module'):\n+ a = a._ppimport_module\n+ if hasattr(a,'_ppimport_attr'):\n+ a = a._ppimport_attr\n+ b.append(ns[0])\n+ del ns[0]\n+ a = getattr(a,b[-1],ppimport('.'.join(b)))\n+\n+ if hasattr(a,'_ppimport_importer') or \\\n+ hasattr(a,'_ppimport_module'):\n+ a = a._ppimport_module\n+ if hasattr(a,'_ppimport_attr'):\n+ a = a._ppimport_attr\n+ return a\n+\n+\n try:\n import pydoc as _pydoc\n except ImportError:\n@@ -297,24 +327,14 @@ def __repr__(self):\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n+\n def _scipy_pydoc_help_call(self,*args,**kwds):\n- new_args = []\n- for a in args:\n- if type(a) is type(''):\n- a = ppimport(a)\n- if hasattr(a,'_ppimport_importer') or \\\n-\t\t hasattr(a,'_ppimport_module'):\n- a = a._ppimport_module\n- if hasattr(a,'_ppimport_attr'):\n- a = a._ppimport_attr\n- new_args.append(a)\n- return _old_pydoc_help_call(self, *new_args, **kwds)\n+ return _old_pydoc_help_call(self, *map(realize,args), **kwds)\n \n import new as _new\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n-\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n", "added_lines": 33, "deleted_lines": 13, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','realize']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef realize(a):\n \"\"\" Return realized object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(realize,args), **kwds)\n\n import new as _new\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n\ttry:\n\t if hasattr(object,'_ppimport_importer') or \\\n\t hasattr(object,'_ppimport_module'):\n object = object._ppimport_module\n if hasattr(object,'_ppimport_attr'):\n\t\tobject = object._ppimport_attr\n\texcept ImportError:\n\t object = object.__class__\n\treturn _old_inspect_getfile(object)\n _inspect.getfile = _inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n new_args = []\n for a in args:\n if type(a) is type(''):\n a = ppimport(a)\n if hasattr(a,'_ppimport_importer') or \\\n\t\t hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n new_args.append(a)\n return _old_pydoc_help_call(self, *new_args, **kwds)\n\n import new as _new\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n\ttry:\n\t if hasattr(object,'_ppimport_importer') or \\\n\t hasattr(object,'_ppimport_module'):\n object = object._ppimport_module\n if hasattr(object,'_ppimport_attr'):\n\t\tobject = object._ppimport_attr\n\texcept ImportError:\n\t object = object.__class__\n\treturn _old_inspect_getfile(object)\n _inspect.getfile = _inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "realize", "long_name": "realize( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 331, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 10, "complexity": 5, "token_count": 54, "parameters": [ "object" ], "start_line": 340, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 12, "complexity": 6, "token_count": 88, "parameters": [ "self", "args", "kwds" ], "start_line": 300, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 10, "complexity": 5, "token_count": 54, "parameters": [ "object" ], "start_line": 320, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 331, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "realize", "long_name": "realize( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 } ], "nloc": 255, "complexity": 72, "token_count": 1567, "diff_parsed": { "added": [ "__all__ = ['ppimport','ppimport_attr','realize']", "def realize(a):", " \"\"\" Return realized object a.", "", " a can be module name, postponed module, postponed modules", " attribute, string representing module attribute, or any", " Python object.", " \"\"\"", " if type(a) is type(''):", " ns = a.split('.')", " a = ppimport(ns[0])", " b = [ns[0]]", " del ns[0]", " while ns:", " if hasattr(a,'_ppimport_importer') or \\", " hasattr(a,'_ppimport_module'):", " a = a._ppimport_module", " if hasattr(a,'_ppimport_attr'):", " a = a._ppimport_attr", " b.append(ns[0])", " del ns[0]", " a = getattr(a,b[-1],ppimport('.'.join(b)))", "", " if hasattr(a,'_ppimport_importer') or \\", " hasattr(a,'_ppimport_module'):", " a = a._ppimport_module", " if hasattr(a,'_ppimport_attr'):", " a = a._ppimport_attr", " return a", "", "", "", " return _old_pydoc_help_call(self, *map(realize,args), **kwds)" ], "deleted": [ "__all__ = ['ppimport','ppimport_attr']", " new_args = []", " for a in args:", " if type(a) is type(''):", " a = ppimport(a)", " if hasattr(a,'_ppimport_importer') or \\", "\t\t hasattr(a,'_ppimport_module'):", " a = a._ppimport_module", " if hasattr(a,'_ppimport_attr'):", " a = a._ppimport_attr", " new_args.append(a)", " return _old_pydoc_help_call(self, *new_args, **kwds)", "" ] } } ] }, { "hash": "1416eaa75e2d5dd0ba845ece4b9bd9fa4b8fba02", "msg": "Renamed realize to ppresolve. Fixed help('scipy.modulename') issue.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-06T06:43:10+00:00", "author_timezone": 0, "committer_date": "2004-05-06T06:43:10+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6f911baa014ebdbcc52916fecfdb5cc8fb8493ec" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 16, "insertions": 17, "lines": 33, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -8,7 +8,7 @@\n $Revision$\n $Date$\n \"\"\"\n-__all__ = ['ppimport','ppimport_attr','realize']\n+__all__ = ['ppimport','ppimport_attr','ppresolve']\n \n import os\n import sys\n@@ -289,8 +289,8 @@ def __repr__(self):\n \n __str__ = __repr__\n \n-def realize(a):\n- \"\"\" Return realized object a.\n+def ppresolve(a):\n+ \"\"\" Return resolved object a.\n \n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n@@ -323,28 +323,29 @@ def realize(a):\n import pydoc as _pydoc\n except ImportError:\n _pydoc = None\n+\n if _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n- _old_pydoc_help_call = _pydoc.help.__class__.__call__\n+ import new as _new\n \n+ _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n- return _old_pydoc_help_call(self, *map(realize,args), **kwds)\n-\n- import new as _new\n+ return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n+\n+ _old_pydoc_Doc_document = _pydoc.Doc.document\n+ def _scipy_pydoc_Doc_document(self,*args,**kwds):\n+ args = (ppresolve(args[0]),) + args[1:]\n+ return _old_pydoc_Doc_document(self,*args,**kwds)\n+ _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n+ None,\n+ _pydoc.Doc)\n+\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n-\ttry:\n-\t if hasattr(object,'_ppimport_importer') or \\\n-\t hasattr(object,'_ppimport_module'):\n- object = object._ppimport_module\n- if hasattr(object,'_ppimport_attr'):\n-\t\tobject = object._ppimport_attr\n-\texcept ImportError:\n-\t object = object.__class__\n-\treturn _old_inspect_getfile(object)\n+\treturn _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _inspect_getfile\n", "added_lines": 17, "deleted_lines": 16, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n\treturn _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','realize']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef realize(a):\n \"\"\" Return realized object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(realize,args), **kwds)\n\n import new as _new\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n\ttry:\n\t if hasattr(object,'_ppimport_importer') or \\\n\t hasattr(object,'_ppimport_module'):\n object = object._ppimport_module\n if hasattr(object,'_ppimport_attr'):\n\t\tobject = object._ppimport_attr\n\texcept ImportError:\n\t object = object.__class__\n\treturn _old_inspect_getfile(object)\n _inspect.getfile = _inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 333, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 340, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 349, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "realize", "long_name": "realize( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 331, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 10, "complexity": 5, "token_count": 54, "parameters": [ "object" ], "start_line": 340, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 349, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "realize", "long_name": "realize( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 340, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 333, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 254, "complexity": 69, "token_count": 1592, "diff_parsed": { "added": [ "__all__ = ['ppimport','ppimport_attr','ppresolve']", "def ppresolve(a):", " \"\"\" Return resolved object a.", "", " import new as _new", " _old_pydoc_help_call = _pydoc.help.__class__.__call__", " return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)", "", " _old_pydoc_Doc_document = _pydoc.Doc.document", " def _scipy_pydoc_Doc_document(self,*args,**kwds):", " args = (ppresolve(args[0]),) + args[1:]", " return _old_pydoc_Doc_document(self,*args,**kwds)", " _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,", " None,", " _pydoc.Doc)", "", "\treturn _old_inspect_getfile(ppresolve(object))" ], "deleted": [ "__all__ = ['ppimport','ppimport_attr','realize']", "def realize(a):", " \"\"\" Return realized object a.", " _old_pydoc_help_call = _pydoc.help.__class__.__call__", " return _old_pydoc_help_call(self, *map(realize,args), **kwds)", "", " import new as _new", "\ttry:", "\t if hasattr(object,'_ppimport_importer') or \\", "\t hasattr(object,'_ppimport_module'):", " object = object._ppimport_module", " if hasattr(object,'_ppimport_attr'):", "\t\tobject = object._ppimport_attr", "\texcept ImportError:", "\t object = object.__class__", "\treturn _old_inspect_getfile(object)" ] } } ] }, { "hash": "7a6dba8288dc9fb908454acd41c0d0a210fc0538", "msg": "Also pydoc.describe needs ppresolve wrapper to get title right.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-06T07:02:28+00:00", "author_timezone": 0, "committer_date": "2004-05-06T07:02:28+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "1416eaa75e2d5dd0ba845ece4b9bd9fa4b8fba02" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 2, "insertions": 7, "lines": 9, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -344,8 +344,13 @@ def _scipy_pydoc_Doc_document(self,*args,**kwds):\n None,\n _pydoc.Doc)\n \n+ _old_pydoc_describe = _pydoc.describe\n+ def _scipy_pydoc_describe(object):\n+ return _old_pydoc_describe(ppresolve(object))\n+ _pydoc.describe = _scipy_pydoc_describe\n+\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n- def _inspect_getfile(object):\n+ def _scipy_inspect_getfile(object):\n \treturn _old_inspect_getfile(ppresolve(object))\n- _inspect.getfile = _inspect_getfile\n+ _inspect.getfile = _scipy_inspect_getfile\n", "added_lines": 7, "deleted_lines": 2, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n\treturn _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _inspect_getfile(object):\n\treturn _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 333, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 340, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 348, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 354, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 333, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 340, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 349, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 348, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 354, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_inspect_getfile", "long_name": "_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 349, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 258, "complexity": 70, "token_count": 1616, "diff_parsed": { "added": [ " _old_pydoc_describe = _pydoc.describe", " def _scipy_pydoc_describe(object):", " return _old_pydoc_describe(ppresolve(object))", " _pydoc.describe = _scipy_pydoc_describe", "", " def _scipy_inspect_getfile(object):", " _inspect.getfile = _scipy_inspect_getfile" ], "deleted": [ " def _inspect_getfile(object):", " _inspect.getfile = _inspect_getfile" ] } } ] }, { "hash": "2c114c6edb99f2e6922e199d42063ffa37709f20", "msg": "Added debugging hooks.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-09T07:14:18+00:00", "author_timezone": 0, "committer_date": "2004-05-09T07:14:18+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7a6dba8288dc9fb908454acd41c0d0a210fc0538" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 5, "insertions": 17, "lines": 22, "files": 1, "dmm_unit_size": 0.1, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.9, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -16,6 +16,8 @@\n import types\n import traceback\n \n+DEBUG=0\n+\n _ppimport_is_enabled = 1\n def enable():\n \"\"\" Enable postponed importing.\"\"\"\n@@ -127,6 +129,7 @@ def ppimport(name):\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n+\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n@@ -187,7 +190,7 @@ def ppimport(name):\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n \n- loader = _ModuleLoader(fullname,location)\n+ loader = _ModuleLoader(fullname,location,p_frame=p_frame)\n if _ppimport_is_enabled:\n return loader\n \n@@ -197,11 +200,12 @@ def ppimport(name):\n class _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n \n- def __init__(self,name,location):\n+ def __init__(self,name,location,p_frame=None):\n \n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n+ self.__dict__['_ppimport_p_frame'] = p_frame\n \n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n@@ -238,10 +242,18 @@ def _ppimport_importer(self):\n # uninstall loader\n del sys.modules[name]\n \n- #print 'Executing postponed import for %s' %(name)\n+ if DEBUG:\n+ print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n- except: # ImportError:\n+ except Exception,msg: # ImportError:\n+ p_frame = self.__dict__.get('_ppimport_p_frame',None)\n+ if p_frame:\n+ print 'ppimport(%s) caller locals:' % (repr(name))\n+ for k in ['__name__','__file__']:\n+ v = p_frame.f_locals.get(k,None)\n+ if v is not None:\n+ print '%s=%s' % (k,v)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n \n@@ -352,5 +364,5 @@ def _scipy_pydoc_describe(object):\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n-\treturn _old_inspect_getfile(ppresolve(object))\n+ return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "added_lines": 17, "deleted_lines": 5, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=p_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n print 'ppimport(%s) caller locals:' % (repr(name))\n for k in ['__name__','__file__']:\n v = p_frame.f_locals.get(k,None)\n if v is not None:\n print '%s=%s' % (k,v)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n #print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except: # ImportError:\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n\treturn _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 317, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 14, "complexity": 3, "token_count": 131, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 203, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 34, "complexity": 9, "token_count": 244, "parameters": [ "self" ], "start_line": 227, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 271, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 278, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 285, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 304, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 345, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 352, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 360, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 366, "end_line": 367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 33, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 50, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 73, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 89, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 108, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 113, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 313, "parameters": [ "name" ], "start_line": 121, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 25, "complexity": 5, "token_count": 173, "parameters": [ "self" ], "start_line": 223, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 266, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 273, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 292, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 333, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 340, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 348, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 354, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self , name , location )", "filename": "ppimport.py", "nloc": 13, "complexity": 3, "token_count": 119, "parameters": [ "self", "name", "location" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 34, "complexity": 9, "token_count": 244, "parameters": [ "self" ], "start_line": 227, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 366, "end_line": 367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 317, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 14, "complexity": 3, "token_count": 131, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 203, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 } ], "nloc": 269, "complexity": 74, "token_count": 1706, "diff_parsed": { "added": [ "DEBUG=0", "", "", " loader = _ModuleLoader(fullname,location,p_frame=p_frame)", " def __init__(self,name,location,p_frame=None):", " self.__dict__['_ppimport_p_frame'] = p_frame", " if DEBUG:", " print 'Executing postponed import for %s' %(name)", " except Exception,msg: # ImportError:", " p_frame = self.__dict__.get('_ppimport_p_frame',None)", " if p_frame:", " print 'ppimport(%s) caller locals:' % (repr(name))", " for k in ['__name__','__file__']:", " v = p_frame.f_locals.get(k,None)", " if v is not None:", " print '%s=%s' % (k,v)", " return _old_inspect_getfile(ppresolve(object))" ], "deleted": [ " loader = _ModuleLoader(fullname,location)", " def __init__(self,name,location):", " #print 'Executing postponed import for %s' %(name)", " except: # ImportError:", "\treturn _old_inspect_getfile(ppresolve(object))" ] } } ] }, { "hash": "91b24babbe5dd3b09dfdf2ff08ee8974b6d59290", "msg": "Fixed bug where targets of different extensions had the same file name and so caused silent name conflicts.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-09T18:08:51+00:00", "author_timezone": 0, "committer_date": "2004-05-09T18:08:51+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "2c114c6edb99f2e6922e199d42063ffa37709f20" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 2, "insertions": 7, "lines": 9, "files": 2, "dmm_unit_size": 0.16666666666666666, "dmm_unit_complexity": 0.16666666666666666, "dmm_unit_interfacing": 0.16666666666666666, "modified_files": [ { "old_path": "scipy_distutils/command/build_src.py", "new_path": "scipy_distutils/command/build_src.py", "filename": "build_src.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -13,7 +13,6 @@\n from scipy_distutils.misc_util import fortran_ext_match, all_strings\n from scipy_distutils.from_template import process_str\n \n-\n class build_src(build_ext.build_ext):\n \n description = \"build sources from SWIG, F2PY files or a function\"\n@@ -154,7 +153,12 @@ def generate_sources(self, sources, extension):\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n- build_dir = self.build_src\n+ if type(extension) is type(()):\n+ name = extension[0]\n+ else:\n+ name = extension.name\n+ build_dir = os.path.join(*([self.build_src]\\\n+ +name.split('.')[:-1]))\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n", "added_lines": 6, "deleted_lines": 2, "source_code": "\"\"\" Build swig, f2py, weave, sources.\n\"\"\"\n\nimport os\nimport re\n\nfrom distutils.cmd import Command\nfrom distutils.command import build_ext, build_py\nfrom distutils.util import convert_path\nfrom distutils.dep_util import newer_group, newer\n\nfrom scipy_distutils import log\nfrom scipy_distutils.misc_util import fortran_ext_match, all_strings\nfrom scipy_distutils.from_template import process_str\n\nclass build_src(build_ext.build_ext):\n\n description = \"build sources from SWIG, F2PY files or a function\"\n\n user_options = [\n ('build-src=', 'd', \"directory to \\\"build\\\" sources to\"),\n ('f2pyflags=', None, \"additonal flags to f2py\"),\n ('swigflags=', None, \"additional flags to swig\"),\n ('force', 'f', \"forcibly build everything (ignore file timestamps)\"),\n ('inplace', 'i',\n \"ignore build-lib and put compiled extensions into the source \" +\n \"directory alongside your pure Python modules\"),\n ]\n\n boolean_options = ['force','inplace']\n\n help_options = []\n\n def initialize_options(self):\n self.extensions = None\n self.package = None\n self.py_modules = None\n self.build_src = None\n self.build_lib = None\n self.build_base = None\n self.force = None\n self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n return\n\n def finalize_options(self):\n self.set_undefined_options('build',\n ('build_base', 'build_base'),\n ('build_lib', 'build_lib'),\n ('force', 'force'))\n if self.package is None:\n self.package = self.distribution.ext_package\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules\n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n if self.inplace is None:\n build_ext = self.get_finalized_command('build_ext')\n self.inplace = build_ext.inplace\n\n # py_modules is used in build_py.find_package_modules\n self.py_modules = {}\n\n if self.f2pyflags is None:\n self.f2pyflags = []\n else:\n self.f2pyflags = self.f2pyflags.split() # XXX spaces??\n\n if self.swigflags is None:\n self.swigflags = []\n else:\n self.swigflags = self.swigflags.split() # XXX spaces??\n return\n\n def run(self):\n if not (self.extensions or self.libraries):\n return\n self.build_sources()\n return\n\n def build_sources(self):\n self.check_extensions_list(self.extensions)\n\n for ext in self.extensions:\n self.build_extension_sources(ext)\n\n for libname_info in self.libraries:\n self.build_library_sources(*libname_info)\n\n return\n\n def build_library_sources(self, lib_name, build_info):\n sources = list(build_info.get('sources',[]))\n\n if not sources:\n return\n\n log.info('building library \"%s\" sources' % (lib_name))\n\n sources = self.generate_sources(sources, (lib_name, build_info))\n\n build_info['sources'] = sources\n return\n\n def build_extension_sources(self, ext):\n sources = list(ext.sources)\n\n log.info('building extension \"%s\" sources' % (ext.name))\n\n fullname = self.get_ext_fullname(ext.name)\n\n modpath = fullname.split('.')\n package = '.'.join(modpath[0:-1])\n\n if self.inplace:\n build_py = self.get_finalized_command('build_py')\n self.ext_target_dir = build_py.get_package_dir(package)\n\n sources = self.generate_sources(sources, ext)\n\n sources = self.template_sources(sources, ext)\n \n sources = self.swig_sources(sources, ext)\n\n sources = self.f2py_sources(sources, ext)\n\n sources, py_files = self.filter_py_files(sources)\n\n if not self.py_modules.has_key(package):\n self.py_modules[package] = []\n modules = []\n for f in py_files:\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n self.py_modules[package] += modules\n\n ext.sources = sources\n return\n\n def generate_sources(self, sources, extension):\n new_sources = []\n func_sources = []\n for source in sources:\n if type(source) is type(''):\n new_sources.append(source)\n else:\n func_sources.append(source)\n if not func_sources:\n return new_sources\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n if type(extension) is type(()):\n name = extension[0]\n else:\n name = extension.name\n build_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n if type(source) is type([]):\n [log.info(\" adding '%s' to sources.\" % (s)) for s in source]\n new_sources.extend(source)\n else:\n log.info(\" adding '%s' to sources.\" % (source))\n new_sources.append(source)\n return new_sources\n\n def filter_py_files(self, sources):\n new_sources = []\n py_files = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext=='.py': \n py_files.append(source)\n else:\n new_sources.append(source)\n return new_sources, py_files\n\n def template_sources(self, sources, extension):\n new_sources = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.src': # Template file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n self.mkpath(target_dir)\n target_file = os.path.join(target_dir,os.path.basename(base))\n if (self.force or newer(source, target_file)):\n fid = open(source)\n outstr = process_str(fid.read())\n fid.close()\n fid = open(target_file,'w')\n fid.write(outstr)\n fid.close()\n new_sources.append(target_file)\n else:\n new_sources.append(source)\n return new_sources \n \n def f2py_sources(self, sources, extension):\n new_sources = []\n f2py_sources = []\n f_sources = []\n f2py_targets = {}\n target_dirs = []\n ext_name = extension.name.split('.')[-1]\n skip_f2py = 0\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.pyf': # F2PY interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n if os.path.isfile(source):\n name = get_f2py_modulename(source)\n assert name==ext_name,'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name`\n target_file = os.path.join(target_dir,name+'module.c')\n else:\n log.debug(' source %s does not exist: skipping f2py\\'ing.' \\\n % (source))\n name = ext_name\n skip_f2py = 1\n target_file = os.path.join(target_dir,name+'module.c')\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %smodule.c was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = os.path.join(target_dir,name+'module.c')\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n new_sources.append(target_file)\n elif fortran_ext_match(ext):\n f_sources.append(source)\n else:\n new_sources.append(source)\n\n if not (f2py_sources or f_sources):\n return new_sources\n\n map(self.mkpath, target_dirs)\n\n f2py_options = extension.f2py_options + self.f2pyflags\n if f2py_sources:\n assert len(f2py_sources)==1,\\\n 'only one .pyf file is allowed per extension module but got'\\\n ' more:'+`f2py_sources`\n source = f2py_sources[0]\n target_file = f2py_targets[source]\n target_dir = os.path.dirname(target_file)\n depends = [source] + extension.depends\n if (self.force or newer_group(depends, target_file,'newer')) \\\n and not skip_f2py:\n log.info(\"f2py: %s\" % (source))\n import f2py2e\n f2py2e.run_main(f2py_options + ['--build-dir',target_dir,source])\n else:\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n target_dir = self.build_src\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n if (self.force or newer_group(depends, target_file, 'newer')) \\\n and not skip_f2py:\n import f2py2e\n log.info(\"f2py:> %s\" % (target_file))\n self.mkpath(target_dir)\n f2py2e.run_main(f2py_options + ['--lower',\n '--build-dir',target_dir]+\\\n ['-m',ext_name]+f_sources)\n else:\n log.debug(\" skipping f2py fortran files for '%s' (up-to-date)\"\\\n % (target_file))\n\n assert os.path.isfile(target_file),`target_file`+' missing'\n\n target_c = os.path.join(self.build_src,'fortranobject.c')\n target_h = os.path.join(self.build_src,'fortranobject.h')\n log.info(\" adding '%s' to sources.\" % (target_c))\n new_sources.append(target_c)\n if self.build_src not in extension.include_dirs:\n log.info(\" adding '%s' to include_dirs.\" \\\n % (self.build_src))\n extension.include_dirs.append(self.build_src)\n\n if not skip_f2py:\n import f2py2e\n d = os.path.dirname(f2py2e.__file__)\n source_c = os.path.join(d,'src','fortranobject.c')\n source_h = os.path.join(d,'src','fortranobject.h')\n if newer(source_c,target_c) or newer(source_h,target_h):\n self.mkpath(os.path.dirname(target_c))\n self.copy_file(source_c,target_c)\n self.copy_file(source_h,target_h)\n else:\n assert os.path.isfile(target_c),`target_c` + ' missing'\n assert os.path.isfile(target_h),`target_h` + ' missing'\n \n for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']:\n filename = os.path.join(target_dir,ext_name + name_ext)\n if os.path.isfile(filename):\n log.info(\" adding '%s' to sources.\" % (filename))\n f_sources.append(filename)\n\n return new_sources + f_sources\n\n def swig_sources(self, sources, extension):\n new_sources = []\n swig_sources = []\n swig_targets = {}\n target_dirs = []\n py_files = [] # swig generated .py files\n target_ext = '.c'\n typ = None\n is_cpp = 0\n skip_swig = 0\n ext_name = extension.name.split('.')[-1]\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.i': # SWIG interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n py_target_dir = self.ext_target_dir\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n py_target_dir = target_dir\n if os.path.isfile(source):\n name = get_swig_modulename(source)\n assert name==ext_name[1:],'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name[1:]`\n if typ is None:\n typ = get_swig_target(source)\n is_cpp = typ=='c++'\n if is_cpp:\n target_ext = '.cpp'\n else:\n assert typ == get_swig_target(source),`typ`\n target_file = os.path.join(target_dir,'%s_wrap%s' \\\n % (name, target_ext))\n else:\n log.debug(' source %s does not exist: skipping swig\\'ing.' \\\n % (source))\n name = ext_name[1:]\n skip_swig = 1\n target_file = _find_swig_target(target_dir, name)\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %s_wrap.{c,cpp} was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = _find_swig_target(target_dir, name)\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n py_files.append(os.path.join(py_target_dir, name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n else:\n new_sources.append(source)\n\n if not swig_sources:\n return new_sources\n\n if skip_swig:\n return new_sources + py_files\n\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n if is_cpp:\n swig_cmd.append('-c++')\n for d in extension.include_dirs:\n swig_cmd.append('-I'+d)\n for source in swig_sources:\n target = swig_targets[source]\n depends = [source] + extension.depends\n if self.force or newer_group(depends, target, 'newer'):\n log.info(\"%s: %s\" % (os.path.basename(swig) \\\n + (is_cpp and '++' or ''), source))\n self.spawn(swig_cmd + self.swigflags \\\n + [\"-o\", target, '-outdir', py_target_dir, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\n\ndef appendpath(prefix,path):\n if os.path.isabs(path):\n absprefix = os.path.abspath(prefix)\n d = os.path.commonprefix([absprefix,path])\n subpath = path[len(d):]\n assert not os.path.isabs(subpath),`subpath`\n return os.path.join(prefix,subpath)\n return os.path.join(prefix, path)\n\n#### SWIG related auxiliary functions ####\n_swig_module_name_match = re.compile(r'\\s*%module\\s*(?P[\\w_]+)',\n re.I).match\n_has_c_header = re.compile(r'-[*]-\\s*c\\s*-[*]-',re.I).search\n_has_cpp_header = re.compile(r'-[*]-\\s*c[+][+]\\s*-[*]-',re.I).search\n\ndef get_swig_target(source):\n f = open(source,'r')\n result = 'c'\n line = f.readline()\n if _has_cpp_header(line):\n result = 'c++'\n if _has_c_header(line):\n result = 'c'\n f.close()\n return result\n\ndef get_swig_modulename(source):\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _swig_module_name_match(line)\n if m:\n name = m.group('name')\n break\n f.close()\n return name\n\ndef _find_swig_target(target_dir,name):\n for ext in ['.cpp','.c']:\n target = os.path.join(target_dir,'%s_wrap%s' % (name, ext))\n if os.path.isfile(target):\n break\n return target\n\n#### F2PY related auxiliary functions ####\n\n_f2py_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',\n re.I).match\n_f2py_user_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?'\\\n '__user__[\\w_]*)',re.I).match\n\ndef get_f2py_modulename(source):\n name = None\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _f2py_module_name_match(line)\n if m:\n if _f2py_user_module_name_match(line): # skip *__user__* names\n continue\n name = m.group('name')\n break\n f.close()\n return name\n\n##########################################\n", "source_code_before": "\"\"\" Build swig, f2py, weave, sources.\n\"\"\"\n\nimport os\nimport re\n\nfrom distutils.cmd import Command\nfrom distutils.command import build_ext, build_py\nfrom distutils.util import convert_path\nfrom distutils.dep_util import newer_group, newer\n\nfrom scipy_distutils import log\nfrom scipy_distutils.misc_util import fortran_ext_match, all_strings\nfrom scipy_distutils.from_template import process_str\n\n\nclass build_src(build_ext.build_ext):\n\n description = \"build sources from SWIG, F2PY files or a function\"\n\n user_options = [\n ('build-src=', 'd', \"directory to \\\"build\\\" sources to\"),\n ('f2pyflags=', None, \"additonal flags to f2py\"),\n ('swigflags=', None, \"additional flags to swig\"),\n ('force', 'f', \"forcibly build everything (ignore file timestamps)\"),\n ('inplace', 'i',\n \"ignore build-lib and put compiled extensions into the source \" +\n \"directory alongside your pure Python modules\"),\n ]\n\n boolean_options = ['force','inplace']\n\n help_options = []\n\n def initialize_options(self):\n self.extensions = None\n self.package = None\n self.py_modules = None\n self.build_src = None\n self.build_lib = None\n self.build_base = None\n self.force = None\n self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n return\n\n def finalize_options(self):\n self.set_undefined_options('build',\n ('build_base', 'build_base'),\n ('build_lib', 'build_lib'),\n ('force', 'force'))\n if self.package is None:\n self.package = self.distribution.ext_package\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules\n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n if self.inplace is None:\n build_ext = self.get_finalized_command('build_ext')\n self.inplace = build_ext.inplace\n\n # py_modules is used in build_py.find_package_modules\n self.py_modules = {}\n\n if self.f2pyflags is None:\n self.f2pyflags = []\n else:\n self.f2pyflags = self.f2pyflags.split() # XXX spaces??\n\n if self.swigflags is None:\n self.swigflags = []\n else:\n self.swigflags = self.swigflags.split() # XXX spaces??\n return\n\n def run(self):\n if not (self.extensions or self.libraries):\n return\n self.build_sources()\n return\n\n def build_sources(self):\n self.check_extensions_list(self.extensions)\n\n for ext in self.extensions:\n self.build_extension_sources(ext)\n\n for libname_info in self.libraries:\n self.build_library_sources(*libname_info)\n\n return\n\n def build_library_sources(self, lib_name, build_info):\n sources = list(build_info.get('sources',[]))\n\n if not sources:\n return\n\n log.info('building library \"%s\" sources' % (lib_name))\n\n sources = self.generate_sources(sources, (lib_name, build_info))\n\n build_info['sources'] = sources\n return\n\n def build_extension_sources(self, ext):\n sources = list(ext.sources)\n\n log.info('building extension \"%s\" sources' % (ext.name))\n\n fullname = self.get_ext_fullname(ext.name)\n\n modpath = fullname.split('.')\n package = '.'.join(modpath[0:-1])\n\n if self.inplace:\n build_py = self.get_finalized_command('build_py')\n self.ext_target_dir = build_py.get_package_dir(package)\n\n sources = self.generate_sources(sources, ext)\n\n sources = self.template_sources(sources, ext)\n \n sources = self.swig_sources(sources, ext)\n\n sources = self.f2py_sources(sources, ext)\n\n sources, py_files = self.filter_py_files(sources)\n\n if not self.py_modules.has_key(package):\n self.py_modules[package] = []\n modules = []\n for f in py_files:\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n self.py_modules[package] += modules\n\n ext.sources = sources\n return\n\n def generate_sources(self, sources, extension):\n new_sources = []\n func_sources = []\n for source in sources:\n if type(source) is type(''):\n new_sources.append(source)\n else:\n func_sources.append(source)\n if not func_sources:\n return new_sources\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n build_dir = self.build_src\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n if type(source) is type([]):\n [log.info(\" adding '%s' to sources.\" % (s)) for s in source]\n new_sources.extend(source)\n else:\n log.info(\" adding '%s' to sources.\" % (source))\n new_sources.append(source)\n return new_sources\n\n def filter_py_files(self, sources):\n new_sources = []\n py_files = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext=='.py': \n py_files.append(source)\n else:\n new_sources.append(source)\n return new_sources, py_files\n\n def template_sources(self, sources, extension):\n new_sources = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.src': # Template file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n self.mkpath(target_dir)\n target_file = os.path.join(target_dir,os.path.basename(base))\n if (self.force or newer(source, target_file)):\n fid = open(source)\n outstr = process_str(fid.read())\n fid.close()\n fid = open(target_file,'w')\n fid.write(outstr)\n fid.close()\n new_sources.append(target_file)\n else:\n new_sources.append(source)\n return new_sources \n \n def f2py_sources(self, sources, extension):\n new_sources = []\n f2py_sources = []\n f_sources = []\n f2py_targets = {}\n target_dirs = []\n ext_name = extension.name.split('.')[-1]\n skip_f2py = 0\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.pyf': # F2PY interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n if os.path.isfile(source):\n name = get_f2py_modulename(source)\n assert name==ext_name,'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name`\n target_file = os.path.join(target_dir,name+'module.c')\n else:\n log.debug(' source %s does not exist: skipping f2py\\'ing.' \\\n % (source))\n name = ext_name\n skip_f2py = 1\n target_file = os.path.join(target_dir,name+'module.c')\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %smodule.c was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = os.path.join(target_dir,name+'module.c')\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n new_sources.append(target_file)\n elif fortran_ext_match(ext):\n f_sources.append(source)\n else:\n new_sources.append(source)\n\n if not (f2py_sources or f_sources):\n return new_sources\n\n map(self.mkpath, target_dirs)\n\n f2py_options = extension.f2py_options + self.f2pyflags\n if f2py_sources:\n assert len(f2py_sources)==1,\\\n 'only one .pyf file is allowed per extension module but got'\\\n ' more:'+`f2py_sources`\n source = f2py_sources[0]\n target_file = f2py_targets[source]\n target_dir = os.path.dirname(target_file)\n depends = [source] + extension.depends\n if (self.force or newer_group(depends, target_file,'newer')) \\\n and not skip_f2py:\n log.info(\"f2py: %s\" % (source))\n import f2py2e\n f2py2e.run_main(f2py_options + ['--build-dir',target_dir,source])\n else:\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n target_dir = self.build_src\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n if (self.force or newer_group(depends, target_file, 'newer')) \\\n and not skip_f2py:\n import f2py2e\n log.info(\"f2py:> %s\" % (target_file))\n self.mkpath(target_dir)\n f2py2e.run_main(f2py_options + ['--lower',\n '--build-dir',target_dir]+\\\n ['-m',ext_name]+f_sources)\n else:\n log.debug(\" skipping f2py fortran files for '%s' (up-to-date)\"\\\n % (target_file))\n\n assert os.path.isfile(target_file),`target_file`+' missing'\n\n target_c = os.path.join(self.build_src,'fortranobject.c')\n target_h = os.path.join(self.build_src,'fortranobject.h')\n log.info(\" adding '%s' to sources.\" % (target_c))\n new_sources.append(target_c)\n if self.build_src not in extension.include_dirs:\n log.info(\" adding '%s' to include_dirs.\" \\\n % (self.build_src))\n extension.include_dirs.append(self.build_src)\n\n if not skip_f2py:\n import f2py2e\n d = os.path.dirname(f2py2e.__file__)\n source_c = os.path.join(d,'src','fortranobject.c')\n source_h = os.path.join(d,'src','fortranobject.h')\n if newer(source_c,target_c) or newer(source_h,target_h):\n self.mkpath(os.path.dirname(target_c))\n self.copy_file(source_c,target_c)\n self.copy_file(source_h,target_h)\n else:\n assert os.path.isfile(target_c),`target_c` + ' missing'\n assert os.path.isfile(target_h),`target_h` + ' missing'\n \n for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']:\n filename = os.path.join(target_dir,ext_name + name_ext)\n if os.path.isfile(filename):\n log.info(\" adding '%s' to sources.\" % (filename))\n f_sources.append(filename)\n\n return new_sources + f_sources\n\n def swig_sources(self, sources, extension):\n new_sources = []\n swig_sources = []\n swig_targets = {}\n target_dirs = []\n py_files = [] # swig generated .py files\n target_ext = '.c'\n typ = None\n is_cpp = 0\n skip_swig = 0\n ext_name = extension.name.split('.')[-1]\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.i': # SWIG interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n py_target_dir = self.ext_target_dir\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n py_target_dir = target_dir\n if os.path.isfile(source):\n name = get_swig_modulename(source)\n assert name==ext_name[1:],'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name[1:]`\n if typ is None:\n typ = get_swig_target(source)\n is_cpp = typ=='c++'\n if is_cpp:\n target_ext = '.cpp'\n else:\n assert typ == get_swig_target(source),`typ`\n target_file = os.path.join(target_dir,'%s_wrap%s' \\\n % (name, target_ext))\n else:\n log.debug(' source %s does not exist: skipping swig\\'ing.' \\\n % (source))\n name = ext_name[1:]\n skip_swig = 1\n target_file = _find_swig_target(target_dir, name)\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %s_wrap.{c,cpp} was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = _find_swig_target(target_dir, name)\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n py_files.append(os.path.join(py_target_dir, name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n else:\n new_sources.append(source)\n\n if not swig_sources:\n return new_sources\n\n if skip_swig:\n return new_sources + py_files\n\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n if is_cpp:\n swig_cmd.append('-c++')\n for d in extension.include_dirs:\n swig_cmd.append('-I'+d)\n for source in swig_sources:\n target = swig_targets[source]\n depends = [source] + extension.depends\n if self.force or newer_group(depends, target, 'newer'):\n log.info(\"%s: %s\" % (os.path.basename(swig) \\\n + (is_cpp and '++' or ''), source))\n self.spawn(swig_cmd + self.swigflags \\\n + [\"-o\", target, '-outdir', py_target_dir, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\n\ndef appendpath(prefix,path):\n if os.path.isabs(path):\n absprefix = os.path.abspath(prefix)\n d = os.path.commonprefix([absprefix,path])\n subpath = path[len(d):]\n assert not os.path.isabs(subpath),`subpath`\n return os.path.join(prefix,subpath)\n return os.path.join(prefix, path)\n\n#### SWIG related auxiliary functions ####\n_swig_module_name_match = re.compile(r'\\s*%module\\s*(?P[\\w_]+)',\n re.I).match\n_has_c_header = re.compile(r'-[*]-\\s*c\\s*-[*]-',re.I).search\n_has_cpp_header = re.compile(r'-[*]-\\s*c[+][+]\\s*-[*]-',re.I).search\n\ndef get_swig_target(source):\n f = open(source,'r')\n result = 'c'\n line = f.readline()\n if _has_cpp_header(line):\n result = 'c++'\n if _has_c_header(line):\n result = 'c'\n f.close()\n return result\n\ndef get_swig_modulename(source):\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _swig_module_name_match(line)\n if m:\n name = m.group('name')\n break\n f.close()\n return name\n\ndef _find_swig_target(target_dir,name):\n for ext in ['.cpp','.c']:\n target = os.path.join(target_dir,'%s_wrap%s' % (name, ext))\n if os.path.isfile(target):\n break\n return target\n\n#### F2PY related auxiliary functions ####\n\n_f2py_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',\n re.I).match\n_f2py_user_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?'\\\n '__user__[\\w_]*)',re.I).match\n\ndef get_f2py_modulename(source):\n name = None\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _f2py_module_name_match(line)\n if m:\n if _f2py_user_module_name_match(line): # skip *__user__* names\n continue\n name = m.group('name')\n break\n f.close()\n return name\n\n##########################################\n", "methods": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_src.py", "nloc": 13, "complexity": 1, "token_count": 61, "parameters": [ "self" ], "start_line": 34, "end_line": 46, "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_src.py", "nloc": 25, "complexity": 7, "token_count": 179, "parameters": [ "self" ], "start_line": 48, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_src.py", "nloc": 5, "complexity": 3, "token_count": 24, "parameters": [ "self" ], "start_line": 78, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_sources", "long_name": "build_sources( self )", "filename": "build_src.py", "nloc": 7, "complexity": 3, "token_count": 41, "parameters": [ "self" ], "start_line": 84, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "build_library_sources", "long_name": "build_library_sources( self , lib_name , build_info )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "self", "lib_name", "build_info" ], "start_line": 95, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_extension_sources", "long_name": "build_extension_sources( self , ext )", "filename": "build_src.py", "nloc": 23, "complexity": 4, "token_count": 207, "parameters": [ "self", "ext" ], "start_line": 108, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "generate_sources", "long_name": "generate_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 29, "complexity": 9, "token_count": 193, "parameters": [ "self", "sources", "extension" ], "start_line": 143, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "filter_py_files", "long_name": "filter_py_files( self , sources )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "self", "sources" ], "start_line": 173, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "template_sources", "long_name": "template_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 22, "complexity": 6, "token_count": 166, "parameters": [ "self", "sources", "extension" ], "start_line": 184, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 107, "complexity": 22, "token_count": 822, "parameters": [ "self", "sources", "extension" ], "start_line": 207, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 117, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 80, "complexity": 17, "token_count": 539, "parameters": [ "self", "sources", "extension" ], "start_line": 325, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "appendpath", "long_name": "appendpath( prefix , path )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 87, "parameters": [ "prefix", "path" ], "start_line": 411, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_swig_target", "long_name": "get_swig_target( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 48, "parameters": [ "source" ], "start_line": 426, "end_line": 435, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_swig_modulename", "long_name": "get_swig_modulename( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "source" ], "start_line": 437, "end_line": 446, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "_find_swig_target", "long_name": "_find_swig_target( target_dir , name )", "filename": "build_src.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "target_dir", "name" ], "start_line": 448, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "get_f2py_modulename", "long_name": "get_f2py_modulename( source )", "filename": "build_src.py", "nloc": 13, "complexity": 4, "token_count": 65, "parameters": [ "source" ], "start_line": 462, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 } ], "methods_before": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_src.py", "nloc": 13, "complexity": 1, "token_count": 61, "parameters": [ "self" ], "start_line": 35, "end_line": 47, "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_src.py", "nloc": 25, "complexity": 7, "token_count": 179, "parameters": [ "self" ], "start_line": 49, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_src.py", "nloc": 5, "complexity": 3, "token_count": 24, "parameters": [ "self" ], "start_line": 79, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_sources", "long_name": "build_sources( self )", "filename": "build_src.py", "nloc": 7, "complexity": 3, "token_count": 41, "parameters": [ "self" ], "start_line": 85, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "build_library_sources", "long_name": "build_library_sources( self , lib_name , build_info )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "self", "lib_name", "build_info" ], "start_line": 96, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_extension_sources", "long_name": "build_extension_sources( self , ext )", "filename": "build_src.py", "nloc": 23, "complexity": 4, "token_count": 207, "parameters": [ "self", "ext" ], "start_line": 109, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "generate_sources", "long_name": "generate_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 24, "complexity": 8, "token_count": 143, "parameters": [ "self", "sources", "extension" ], "start_line": 144, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "filter_py_files", "long_name": "filter_py_files( self , sources )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "self", "sources" ], "start_line": 169, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "template_sources", "long_name": "template_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 22, "complexity": 6, "token_count": 166, "parameters": [ "self", "sources", "extension" ], "start_line": 180, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 107, "complexity": 22, "token_count": 822, "parameters": [ "self", "sources", "extension" ], "start_line": 203, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 117, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 80, "complexity": 17, "token_count": 539, "parameters": [ "self", "sources", "extension" ], "start_line": 321, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "appendpath", "long_name": "appendpath( prefix , path )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 87, "parameters": [ "prefix", "path" ], "start_line": 407, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_swig_target", "long_name": "get_swig_target( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 48, "parameters": [ "source" ], "start_line": 422, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_swig_modulename", "long_name": "get_swig_modulename( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "source" ], "start_line": 433, "end_line": 442, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "_find_swig_target", "long_name": "_find_swig_target( target_dir , name )", "filename": "build_src.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "target_dir", "name" ], "start_line": 444, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "get_f2py_modulename", "long_name": "get_f2py_modulename( source )", "filename": "build_src.py", "nloc": 13, "complexity": 4, "token_count": 65, "parameters": [ "source" ], "start_line": 458, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "generate_sources", "long_name": "generate_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 29, "complexity": 9, "token_count": 193, "parameters": [ "self", "sources", "extension" ], "start_line": 143, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 } ], "nloc": 408, "complexity": 92, "token_count": 2864, "diff_parsed": { "added": [ " if type(extension) is type(()):", " name = extension[0]", " else:", " name = extension.name", " build_dir = os.path.join(*([self.build_src]\\", " +name.split('.')[:-1]))" ], "deleted": [ "", " build_dir = self.build_src" ] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -545,6 +545,7 @@ def generate_svn_version_py(extension, build_dir):\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n+ print extension.name\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n", "added_lines": 1, "deleted_lines": 0, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n print extension.name\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 403, "end_line": 493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 495, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 13, "complexity": 2, "token_count": 91, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 559, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 403, "end_line": 493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 495, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 558, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 13, "complexity": 2, "token_count": 91, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "nloc": 416, "complexity": 131, "token_count": 3017, "diff_parsed": { "added": [ " print extension.name" ], "deleted": [] } } ] }, { "hash": "14a9cf6cef58567a2903b94af01f6b2686e0105f", "msg": "Cleanup.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-09T18:10:50+00:00", "author_timezone": 0, "committer_date": "2004-05-09T18:10:50+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "91b24babbe5dd3b09dfdf2ff08ee8974b6d59290" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 11, "insertions": 0, "lines": 11, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.8571428571428571, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -211,16 +211,6 @@ def __init__(self,name,location,p_frame=None):\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n \n- # get additional attributes (doc strings, etc)\n- # from pre_.py file. XXX: remove this code\n- # when new style packaging is implemented.\n- filename = os.path.splitext(location)[0] + '.py'\n- filename = location\n- dirname,basename = os.path.split(filename)\n- preinit = os.path.join(dirname,'pre_'+basename)\n- if os.path.isfile(preinit):\n- execfile(preinit, self.__dict__)\n-\n # install loader\n sys.modules[name] = self\n \n", "added_lines": 0, "deleted_lines": 10, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=p_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n print 'ppimport(%s) caller locals:' % (repr(name))\n for k in ['__name__','__file__']:\n v = p_frame.f_locals.get(k,None)\n if v is not None:\n print '%s=%s' % (k,v)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=p_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # get additional attributes (doc strings, etc)\n # from pre_.py file. XXX: remove this code\n # when new style packaging is implemented.\n filename = os.path.splitext(location)[0] + '.py'\n filename = location\n dirname,basename = os.path.split(filename)\n preinit = os.path.join(dirname,'pre_'+basename)\n if os.path.isfile(preinit):\n execfile(preinit, self.__dict__)\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n print 'ppimport(%s) caller locals:' % (repr(name))\n for k in ['__name__','__file__']:\n v = p_frame.f_locals.get(k,None)\n if v is not None:\n print '%s=%s' % (k,v)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 317, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 203, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 34, "complexity": 9, "token_count": 244, "parameters": [ "self" ], "start_line": 217, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 261, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 268, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 275, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 294, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 335, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 342, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 350, "end_line": 351, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 356, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 317, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 14, "complexity": 3, "token_count": 131, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 203, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 34, "complexity": 9, "token_count": 244, "parameters": [ "self" ], "start_line": 227, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 271, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 278, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 285, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 304, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 345, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 352, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 360, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 366, "end_line": 367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 14, "complexity": 3, "token_count": 131, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 203, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 } ], "nloc": 263, "complexity": 73, "token_count": 1644, "diff_parsed": { "added": [], "deleted": [ " # get additional attributes (doc strings, etc)", " # from pre_.py file. XXX: remove this code", " # when new style packaging is implemented.", " filename = os.path.splitext(location)[0] + '.py'", " filename = location", " dirname,basename = os.path.split(filename)", " preinit = os.path.join(dirname,'pre_'+basename)", " if os.path.isfile(preinit):", " execfile(preinit, self.__dict__)", "" ] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -545,7 +545,6 @@ def generate_svn_version_py(extension, build_dir):\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n- print extension.name\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n", "added_lines": 0, "deleted_lines": 1, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n print extension.name\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 403, "end_line": 493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 495, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 558, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 403, "end_line": 493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 495, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 13, "complexity": 2, "token_count": 91, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 559, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 13, "complexity": 2, "token_count": 91, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "nloc": 415, "complexity": 131, "token_count": 3013, "diff_parsed": { "added": [], "deleted": [ " print extension.name" ] } } ] }, { "hash": "7d34fc5230b2a1df825c65c88cc7c1805803c28a", "msg": "Introduced include_only boolean argument to get_subpackages.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-10T06:59:01+00:00", "author_timezone": 0, "committer_date": "2004-05-10T06:59:01+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "14a9cf6cef58567a2903b94af01f6b2686e0105f" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 0, "insertions": 6, "lines": 6, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -405,6 +405,7 @@ def get_subpackages(path,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n+ include_only=None,\n recursive=None):\n \n \"\"\"\n@@ -428,6 +429,9 @@ def get_subpackages(path,\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n \n+ When include_only is True then only configurations of those\n+ packages are returned that are in include_packages list.\n+\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n@@ -443,6 +447,8 @@ def get_subpackages(path,\n \n if package_name in ignore_packages:\n continue\n+ if include_only and package_name not in include_packages:\n+ continue\n \n sys.path.insert(0,os.path.dirname(info_file))\n try:\n", "added_lines": 6, "deleted_lines": 0, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 403, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 501, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 539, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 564, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , recursive = None )", "filename": "misc_util.py", "nloc": 58, "complexity": 16, "token_count": 434, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "recursive" ], "start_line": 403, "end_line": 493, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 91, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 495, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 533, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 558, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 403, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 } ], "nloc": 418, "complexity": 133, "token_count": 3026, "diff_parsed": { "added": [ " include_only=None,", " When include_only is True then only configurations of those", " packages are returned that are in include_packages list.", "", " if include_only and package_name not in include_packages:", " continue" ], "deleted": [] } } ] }, { "hash": "5f39b86339d1aee2899001bb763389159dd33685", "msg": "Impl. get_build_platlib(). atlas_version is built into temp directory - this should fix bdist_rpm on RedHat systems.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-10T08:19:08+00:00", "author_timezone": 0, "committer_date": "2004-05-10T08:19:08+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7d34fc5230b2a1df825c65c88cc7c1805803c28a" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 1, "insertions": 7, "lines": 8, "files": 2, "dmm_unit_size": 0.8, "dmm_unit_complexity": 0.8, "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": "@@ -247,6 +247,11 @@ def get_build_temp():\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n \n+def get_build_platlib():\n+ from distutils.util import get_platform\n+ plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n+ return os.path.join('build','lib'+plat_specifier)\n+\n class SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n", "added_lines": 5, "deleted_lines": 0, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_build_platlib():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','lib'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "get_build_platlib", "long_name": "get_build_platlib( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 250, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 264, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 277, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 279, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 291, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 300, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 304, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 306, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 316, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 334, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 341, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 348, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 355, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 377, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 397, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 408, "end_line": 504, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 506, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 544, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 569, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 259, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 274, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 286, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 295, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 299, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 301, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 311, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 329, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 336, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 350, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 372, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 392, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 403, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 501, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 539, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 564, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_build_platlib", "long_name": "get_build_platlib( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 250, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "nloc": 422, "complexity": 134, "token_count": 3068, "diff_parsed": { "added": [ "def get_build_platlib():", " from distutils.util import get_platform", " plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])", " return os.path.join('build','lib'+plat_specifier)", "" ], "deleted": [] } }, { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -804,6 +804,7 @@ def calc_info(self):\n \n def get_atlas_version(**config):\n from core import Extension, setup\n+ from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n@@ -819,7 +820,7 @@ def atlas_version_c(extension, build_dir,magic=magic):\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n- extra_args = []\n+ extra_args = ['-b',os.path.join(get_build_temp())]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n", "added_lines": 2, "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\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['-b',os.path.join(get_build_temp())]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,'--cxxflags')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = gdk_pixbuf_2_info()\n c.verbosity = 2\n c.get_info()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,'--cxxflags')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = gdk_pixbuf_2_info()\n c.verbosity = 2\n c.get_info()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 40, "complexity": 1, "token_count": 182, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 269, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 298, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 301, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 26, "complexity": 11, "token_count": 276, "parameters": [ "self", "section", "key" ], "start_line": 338, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 368, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 371, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 374, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 381, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 394, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 404, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 408, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 419, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 430, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 433, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 500, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 507, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 536, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 544, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 628, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 676, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 695, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 702, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 810, "end_line": 819, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 296, "parameters": [ "config" ], "start_line": 805, "end_line": 859, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 864, "end_line": 938, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 943, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1005, "end_line": 1017, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1025, "end_line": 1030, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1032, "end_line": 1067, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1073, "end_line": 1076, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1078, "end_line": 1097, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1104, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1127, "end_line": 1155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1165, "end_line": 1170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1172, "end_line": 1192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1198, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1205, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1238, "end_line": 1241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1242, "end_line": 1245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 433, "parameters": [ "self" ], "start_line": 1247, "end_line": 1300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1358, "end_line": 1382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1386, "end_line": 1402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1404, "end_line": 1412, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 40, "complexity": 1, "token_count": 182, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 269, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 298, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 301, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 26, "complexity": 11, "token_count": 276, "parameters": [ "self", "section", "key" ], "start_line": 338, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 368, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 371, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 374, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 381, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 394, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 404, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 408, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 419, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 430, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 433, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 500, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 507, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 536, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 544, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 628, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 676, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 695, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 702, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 809, "end_line": 818, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 44, "complexity": 9, "token_count": 280, "parameters": [ "config" ], "start_line": 805, "end_line": 858, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 863, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 942, "end_line": 995, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1004, "end_line": 1016, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1024, "end_line": 1029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1031, "end_line": 1066, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1072, "end_line": 1075, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1077, "end_line": 1096, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1103, "end_line": 1124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1126, "end_line": 1154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1164, "end_line": 1169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1171, "end_line": 1191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1197, "end_line": 1202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1204, "end_line": 1226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1237, "end_line": 1240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1241, "end_line": 1244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 433, "parameters": [ "self" ], "start_line": 1246, "end_line": 1299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1357, "end_line": 1381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1385, "end_line": 1401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1403, "end_line": 1411, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 296, "parameters": [ "config" ], "start_line": 805, "end_line": 859, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 } ], "nloc": 1250, "complexity": 261, "token_count": 6925, "diff_parsed": { "added": [ " from misc_util import get_build_temp", " extra_args = ['-b',os.path.join(get_build_temp())]" ], "deleted": [ " extra_args = []" ] } } ] }, { "hash": "038fb06119e7816d30ade395f1dbd4d31d18c5c6", "msg": "Cleanup.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-11T12:41:42+00:00", "author_timezone": 0, "committer_date": "2004-05-11T12:41:42+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5f39b86339d1aee2899001bb763389159dd33685" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/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/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -820,7 +820,7 @@ def atlas_version_c(extension, build_dir,magic=magic):\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n- extra_args = ['-b',os.path.join(get_build_temp())]\n+ extra_args = ['--build-lib',get_build_temp()]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\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\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['--build-lib',get_build_temp()]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,'--cxxflags')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = gdk_pixbuf_2_info()\n c.verbosity = 2\n c.get_info()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python_info\n agg2_info\n wx_info\n gdk_pixbuf_xlib_2_info\n gdk_pixbuf_2_info\n gdk_x11_2_info\n gtkp_x11_2_info\n gtkp_2_info\n xft_info\n freetype2_info\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\n Several *_info classes specify an environment variable to specify\n the locations of software. When setting the corresponding environment\n variable to 'None' then the software will be ignored, even when it\n is available in system.\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\nfrom exec_command import find_executable, exec_command\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n 'wx':wx_info,\n 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,\n 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,\n 'gdk_pixbuf_2':gdk_pixbuf_2_info,\n 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,\n 'gdk_x11_2':gdk_x11_2_info,\n 'gdk-x11-2.0':gdk_x11_2_info,\n 'gtkp_x11_2':gtkp_x11_2_info,\n 'gtk+-x11-2.0':gtkp_x11_2_info,\n 'gtkp_2':gtkp_2_info,\n 'gtk+-2.0':gtkp_2_info,\n 'xft':xft_info,\n 'freetype2':freetype2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if d=='None':\n print 'Disabled',self.__class__.__name__,'(%s is None)' % (self.dir_env_var)\n return []\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n from misc_util import get_build_temp\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = ['-b',os.path.join(get_build_temp())]\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass _pkg_config_info(system_info):\n section = None\n config_env_var = 'PKG_CONFIG'\n default_config_exe = 'pkg-config'\n append_config_exe = ''\n version_macro_name = None\n release_macro_name = None\n version_flag = '--modversion'\n\n def get_config_exe(self):\n if os.environ.has_key(self.config_env_var):\n return os.environ[self.config_env_var]\n return self.default_config_exe\n def get_config_output(self, config_exe, option):\n s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)\n if not s:\n return o\n\n def calc_info(self):\n config_exe = find_executable(self.get_config_exe())\n if not os.path.isfile(config_exe):\n print 'File not found: %s. Cannot determine %s info.' \\\n % (config_exe, self.section)\n return\n info = {}\n macros = []\n libraries = []\n library_dirs = []\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n version = self.get_config_output(config_exe,self.version_flag)\n if version:\n macros.append((self.__class__.__name__.split('.')[-1].upper(),\n '\"\\\\\"%s\\\\\"\"' % (version)))\n if self.version_macro_name:\n macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))\n if self.release_macro_name:\n release = self.get_config_output(config_exe,'--release')\n if release:\n macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(config_exe,'--libs')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-l':\n libraries.append(opt[2:])\n elif opt[:2]=='-L':\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n opts = self.get_config_output(config_exe,'--cxxflags')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n include_dirs.append(opt[2:])\n elif opt[:2]=='-D':\n if '=' in opt:\n n,v = opt[2:].split('=')\n macros.append((n,v))\n else:\n macros.append((opt[2:],None))\n else:\n extra_compile_args.append(opt)\n if macros: dict_append(info, define_macros = macros)\n if libraries: dict_append(info, libraries = libraries)\n if library_dirs: dict_append(info, library_dirs = library_dirs)\n if include_dirs: dict_append(info, include_dirs = include_dirs)\n if extra_link_args: dict_append(info, extra_link_args = extra_link_args)\n if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(_pkg_config_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\n default_config_exe = 'wx-config'\n append_config_exe = ''\n version_macro_name = 'WX_VERSION'\n release_macro_name = 'WX_RELEASE'\n version_flag = '--version'\n\nclass gdk_pixbuf_xlib_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_xlib_2'\n append_config_exe = 'gdk-pixbuf-xlib-2.0'\n version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'\n\nclass gdk_pixbuf_2_info(_pkg_config_info):\n section = 'gdk_pixbuf_2'\n append_config_exe = 'gdk-pixbuf-2.0'\n version_macro_name = 'GDK_PIXBUF_VERSION'\n\nclass gdk_x11_2_info(_pkg_config_info):\n section = 'gdk_x11_2'\n append_config_exe = 'gdk-x11-2.0'\n version_macro_name = 'GDK_X11_VERSION'\n\nclass gtkp_x11_2_info(_pkg_config_info):\n section = 'gtkp_x11_2'\n append_config_exe = 'gtk+-x11-2.0'\n version_macro_name = 'GTK_X11_VERSION'\n\n\nclass gtkp_2_info(_pkg_config_info):\n section = 'gtkp_2'\n append_config_exe = 'gtk+-2.0'\n version_macro_name = 'GTK_VERSION'\n\nclass xft_info(_pkg_config_info):\n section = 'xft'\n append_config_exe = 'xft'\n version_macro_name = 'XFT_VERSION'\n\nclass freetype2_info(_pkg_config_info):\n section = 'freetype2'\n append_config_exe = 'freetype2'\n version_macro_name = 'FREETYPE2_VERSION'\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = gdk_pixbuf_2_info()\n c.verbosity = 2\n c.get_info()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 40, "complexity": 1, "token_count": 182, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 269, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 298, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 301, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 26, "complexity": 11, "token_count": 276, "parameters": [ "self", "section", "key" ], "start_line": 338, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 368, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 371, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 374, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 381, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 394, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 404, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 408, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 419, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 430, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 433, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 500, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 507, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 536, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 544, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 628, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 676, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 695, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 702, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 810, "end_line": 819, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 805, "end_line": 859, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 864, "end_line": 938, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 943, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1005, "end_line": 1017, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1025, "end_line": 1030, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1032, "end_line": 1067, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1073, "end_line": 1076, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1078, "end_line": 1097, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1104, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1127, "end_line": 1155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1165, "end_line": 1170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1172, "end_line": 1192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1198, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1205, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1238, "end_line": 1241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1242, "end_line": 1245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 433, "parameters": [ "self" ], "start_line": 1247, "end_line": 1300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1358, "end_line": 1382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1386, "end_line": 1402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1404, "end_line": 1412, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 40, "complexity": 1, "token_count": 182, "parameters": [ "name", "notfound_action" ], "start_line": 144, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 269, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 298, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 301, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 26, "complexity": 11, "token_count": 276, "parameters": [ "self", "section", "key" ], "start_line": 338, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 368, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 371, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 374, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 381, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 394, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 404, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 408, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 419, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 430, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 433, "end_line": 458, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 500, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 507, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 536, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 544, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 628, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 676, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 695, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 702, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 810, "end_line": 819, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 296, "parameters": [ "config" ], "start_line": 805, "end_line": 859, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 864, "end_line": 938, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 943, "end_line": 996, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 1005, "end_line": 1017, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1025, "end_line": 1030, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1032, "end_line": 1067, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1073, "end_line": 1076, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1078, "end_line": 1097, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1104, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1127, "end_line": 1155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1165, "end_line": 1170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1172, "end_line": 1192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1198, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1205, "end_line": 1227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 1238, "end_line": 1241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_config_output", "long_name": "get_config_output( self , config_exe , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 37, "parameters": [ "self", "config_exe", "option" ], "start_line": 1242, "end_line": 1245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 54, "complexity": 22, "token_count": 433, "parameters": [ "self" ], "start_line": 1247, "end_line": 1300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1358, "end_line": 1382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1386, "end_line": 1402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1404, "end_line": 1412, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 45, "complexity": 9, "token_count": 289, "parameters": [ "config" ], "start_line": 805, "end_line": 859, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 } ], "nloc": 1250, "complexity": 261, "token_count": 6918, "diff_parsed": { "added": [ " extra_args = ['--build-lib',get_build_temp()]" ], "deleted": [ " extra_args = ['-b',os.path.join(get_build_temp())]" ] } } ] }, { "hash": "5d6793a718e91906b1e75665ba78c6e02e6a1370", "msg": "Fixed bugs. More debugging hooks. ppresolve returns its string argument when it is unable to resolve the object and when ignore_failure is true, this fixes few Arnd cases.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-11T12:44:56+00:00", "author_timezone": 0, "committer_date": "2004-05-11T12:44:56+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "038fb06119e7816d30ade395f1dbd4d31d18c5c6" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 14, "insertions": 52, "lines": 66, "files": 1, "dmm_unit_size": 0.08571428571428572, "dmm_unit_complexity": 0.6, "dmm_unit_interfacing": 0.9714285714285714, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -131,7 +131,7 @@ def ppimport(name):\n global _ppimport_is_enabled\n \n level = 1\n- p_frame = _get_frame(level)\n+ parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n@@ -154,7 +154,7 @@ def ppimport(name):\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n- if _ppimport_is_enabled:\n+ if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n \n@@ -184,18 +184,37 @@ def ppimport(name):\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n- if _ppimport_is_enabled:\n+ if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n \n- loader = _ModuleLoader(fullname,location,p_frame=p_frame)\n+ loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n \n return loader._ppimport_importer()\n \n+def _pprint_frame(frame):\n+ filename = frame.f_code.co_filename\n+ lineno = frame.f_lineno\n+ result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n+ if not os.path.isfile(filename):\n+ return result\n+ f = open(filename)\n+ i = 1\n+ line = f.readline()\n+ while line:\n+ line = f.readline()\n+ i = i + 1\n+ if (abs(i-lineno)<2):\n+ result += '#%d: %s\\n' % (i,line.rstrip())\n+ if i>lineno+3:\n+ break\n+ f.close()\n+ return result\n+\n \n class _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n@@ -239,11 +258,18 @@ def _ppimport_importer(self):\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n- print 'ppimport(%s) caller locals:' % (repr(name))\n- for k in ['__name__','__file__']:\n- v = p_frame.f_locals.get(k,None)\n- if v is not None:\n- print '%s=%s' % (k,v)\n+ if DEBUG:\n+ blocks = []\n+ f = p_frame\n+ while f:\n+ blocks.insert(0,_pprint_frame(f))\n+ f = f.f_back\n+ print '='*50\n+ print ' ppimport(%s) traceback' % (repr(name))\n+ print '-'*50\n+ print '\\n'.join(blocks)\n+ print '='*50\n+\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n \n@@ -291,13 +317,19 @@ def __repr__(self):\n \n __str__ = __repr__\n \n-def ppresolve(a):\n+def ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n \n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n+ global _ppimport_is_enabled\n+ if _ppimport_is_enabled:\n+ disable()\n+ a = ppresolve(a,ignore_failure=ignore_failure)\n+ enable()\n+ return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n@@ -311,8 +343,10 @@ def ppresolve(a):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n- a = getattr(a,b[-1],ppimport('.'.join(b)))\n-\n+ #a = getattr(a,b[-1],ppimport('.'.join(b)))\n+ if ignore_failure and not hasattr(a, b[-1]):\n+ return '.'.join(ns+b)\n+ a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n@@ -320,6 +354,8 @@ def ppresolve(a):\n a = a._ppimport_attr\n return a\n \n+def _ppresolve_ignore_failure(a):\n+ return ppresolve(a,ignore_failure=1)\n \n try:\n import pydoc as _pydoc\n@@ -333,14 +369,15 @@ def ppresolve(a):\n \n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n- return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n+ return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n+ **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n \n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n- args = (ppresolve(args[0]),) + args[1:]\n+ args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n@@ -356,3 +393,4 @@ def _scipy_pydoc_describe(object):\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n+\n", "added_lines": 52, "deleted_lines": 14, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _pprint_frame(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n if DEBUG:\n blocks = []\n f = p_frame\n while f:\n blocks.insert(0,_pprint_frame(f))\n f = f.f_back\n print '='*50\n print ' ppimport(%s) traceback' % (repr(name))\n print '-'*50\n print '\\n'.join(blocks)\n print '='*50\n\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n #a = getattr(a,b[-1],ppimport('.'.join(b)))\n if ignore_failure and not hasattr(a, b[-1]):\n return '.'.join(ns+b)\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled:\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=p_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n print 'ppimport(%s) caller locals:' % (repr(name))\n for k in ['__name__','__file__']:\n v = p_frame.f_locals.get(k,None)\n if v is not None:\n print '%s=%s' % (k,v)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n a = getattr(a,b[-1],ppimport('.'.join(b)))\n\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (ppresolve(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "_pprint_frame", "long_name": "_pprint_frame( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 222, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 40, "complexity": 9, "token_count": 257, "parameters": [ "self" ], "start_line": 236, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 294, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 301, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 29, "complexity": 12, "token_count": 197, "parameters": [ "a", "ignore_failure" ], "start_line": 320, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 357, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 371, "end_line": 373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 387, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 393, "end_line": 394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 12, "token_count": 317, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 203, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 34, "complexity": 9, "token_count": 244, "parameters": [ "self" ], "start_line": 217, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 261, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 268, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 275, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 294, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 335, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 342, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 350, "end_line": 351, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 356, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "ppresolve", "long_name": "ppresolve( a )", "filename": "ppimport.py", "nloc": 21, "complexity": 9, "token_count": 156, "parameters": [ "a" ], "start_line": 294, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_pprint_frame", "long_name": "_pprint_frame( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 371, "end_line": 373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 40, "complexity": 9, "token_count": 257, "parameters": [ "self" ], "start_line": 236, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 29, "complexity": 12, "token_count": 197, "parameters": [ "a", "ignore_failure" ], "start_line": 320, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 357, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 } ], "nloc": 298, "complexity": 84, "token_count": 1848, "diff_parsed": { "added": [ " parent_frame = p_frame = _get_frame(level)", " if _ppimport_is_enabled or isinstance(module,types.ModuleType):", " if _ppimport_is_enabled or isinstance(module,types.ModuleType):", " loader = _ModuleLoader(fullname,location,p_frame=parent_frame)", "def _pprint_frame(frame):", " filename = frame.f_code.co_filename", " lineno = frame.f_lineno", " result = '%s in %s:\\n' % (filename,frame.f_code.co_name)", " if not os.path.isfile(filename):", " return result", " f = open(filename)", " i = 1", " line = f.readline()", " while line:", " line = f.readline()", " i = i + 1", " if (abs(i-lineno)<2):", " result += '#%d: %s\\n' % (i,line.rstrip())", " if i>lineno+3:", " break", " f.close()", " return result", "", " if DEBUG:", " blocks = []", " f = p_frame", " while f:", " blocks.insert(0,_pprint_frame(f))", " f = f.f_back", " print '='*50", " print ' ppimport(%s) traceback' % (repr(name))", " print '-'*50", " print '\\n'.join(blocks)", " print '='*50", "", "def ppresolve(a,ignore_failure=None):", " global _ppimport_is_enabled", " if _ppimport_is_enabled:", " disable()", " a = ppresolve(a,ignore_failure=ignore_failure)", " enable()", " return a", " #a = getattr(a,b[-1],ppimport('.'.join(b)))", " if ignore_failure and not hasattr(a, b[-1]):", " return '.'.join(ns+b)", " a = getattr(a,b[-1])", "def _ppresolve_ignore_failure(a):", " return ppresolve(a,ignore_failure=1)", " return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),", " **kwds)", " args = (_ppresolve_ignore_failure(args[0]),) + args[1:]", "" ], "deleted": [ " p_frame = _get_frame(level)", " if _ppimport_is_enabled:", " if _ppimport_is_enabled:", " loader = _ModuleLoader(fullname,location,p_frame=p_frame)", " print 'ppimport(%s) caller locals:' % (repr(name))", " for k in ['__name__','__file__']:", " v = p_frame.f_locals.get(k,None)", " if v is not None:", " print '%s=%s' % (k,v)", "def ppresolve(a):", " a = getattr(a,b[-1],ppimport('.'.join(b)))", "", " return _old_pydoc_help_call(self, *map(ppresolve,args), **kwds)", " args = (ppresolve(args[0]),) + args[1:]" ] } } ] }, { "hash": "d7b3cd5daa9dac6e8e69ca69c27fd8d5e4041d73", "msg": "Refactored code: frame_traceback is quite useful in debugging. Fixed importing all postponed modules when using help().", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-11T16:32:44+00:00", "author_timezone": 0, "committer_date": "2004-05-11T16:32:44+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5d6793a718e91906b1e75665ba78c6e02e6a1370" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 18, "insertions": 19, "lines": 37, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -154,7 +154,7 @@ def ppimport(name):\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n- if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n+ if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n \n@@ -196,7 +196,7 @@ def ppimport(name):\n \n return loader._ppimport_importer()\n \n-def _pprint_frame(frame):\n+def _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n@@ -215,6 +215,17 @@ def _pprint_frame(frame):\n f.close()\n return result\n \n+def frame_traceback(frame):\n+ if not frame:\n+ return\n+ blocks = []\n+ f = frame\n+ while f:\n+ blocks.insert(0,_get_frame_code(f))\n+ f = f.f_back\n+ print '='*50\n+ print '\\n'.join(blocks)\n+ print '='*50 \n \n class _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n@@ -256,20 +267,9 @@ def _ppimport_importer(self):\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n- p_frame = self.__dict__.get('_ppimport_p_frame',None)\n- if p_frame:\n- if DEBUG:\n- blocks = []\n- f = p_frame\n- while f:\n- blocks.insert(0,_pprint_frame(f))\n- f = f.f_back\n- print '='*50\n- print ' ppimport(%s) traceback' % (repr(name))\n- print '-'*50\n- print '\\n'.join(blocks)\n- print '='*50\n-\n+ if DEBUG:\n+ p_frame = self.__dict__.get('_ppimport_p_frame',None)\n+ frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n \n@@ -343,7 +343,6 @@ def ppresolve(a,ignore_failure=None):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n- #a = getattr(a,b[-1],ppimport('.'.join(b)))\n if ignore_failure and not hasattr(a, b[-1]):\n return '.'.join(ns+b)\n a = getattr(a,b[-1])\n@@ -391,6 +390,8 @@ def _scipy_pydoc_describe(object):\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n- return _old_inspect_getfile(ppresolve(object))\n+ if isinstance(object,_ModuleLoader):\n+ return object.__dict__['__file__']\n+ return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n \n", "added_lines": 19, "deleted_lines": 18, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n return '.'.join(ns+b)\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _pprint_frame(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n if p_frame:\n if DEBUG:\n blocks = []\n f = p_frame\n while f:\n blocks.insert(0,_pprint_frame(f))\n f = f.f_back\n print '='*50\n print ' ppimport(%s) traceback' % (repr(name))\n print '-'*50\n print '\\n'.join(blocks)\n print '='*50\n\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n #a = getattr(a,b[-1],ppimport('.'.join(b)))\n if ignore_failure and not hasattr(a, b[-1]):\n return '.'.join(ns+b)\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n return _old_inspect_getfile(ppresolve(object))\n _inspect.getfile = _scipy_inspect_getfile\n\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 218, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 233, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 247, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 294, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 301, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 29, "complexity": 12, "token_count": 197, "parameters": [ "a", "ignore_failure" ], "start_line": 320, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 356, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 370, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 378, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 386, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "object" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "_pprint_frame", "long_name": "_pprint_frame( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 222, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 40, "complexity": 9, "token_count": 257, "parameters": [ "self" ], "start_line": 236, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 294, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 301, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 29, "complexity": 12, "token_count": 197, "parameters": [ "a", "ignore_failure" ], "start_line": 320, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 357, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 371, "end_line": 373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 387, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 393, "end_line": 394, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "_pprint_frame", "long_name": "_pprint_frame( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 247, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 29, "complexity": 12, "token_count": 197, "parameters": [ "a", "ignore_failure" ], "start_line": 320, "end_line": 355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 218, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "object" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 } ], "nloc": 301, "complexity": 86, "token_count": 1859, "diff_parsed": { "added": [ " if _ppimport_is_enabled or isinstance(module, types.ModuleType):", "def _get_frame_code(frame):", "def frame_traceback(frame):", " if not frame:", " return", " blocks = []", " f = frame", " while f:", " blocks.insert(0,_get_frame_code(f))", " f = f.f_back", " print '='*50", " print '\\n'.join(blocks)", " print '='*50", " if DEBUG:", " p_frame = self.__dict__.get('_ppimport_p_frame',None)", " frame_traceback(p_frame)", " if isinstance(object,_ModuleLoader):", " return object.__dict__['__file__']", " return _old_inspect_getfile(object)" ], "deleted": [ " if _ppimport_is_enabled or isinstance(module,types.ModuleType):", "def _pprint_frame(frame):", " p_frame = self.__dict__.get('_ppimport_p_frame',None)", " if p_frame:", " if DEBUG:", " blocks = []", " f = p_frame", " while f:", " blocks.insert(0,_pprint_frame(f))", " f = f.f_back", " print '='*50", " print ' ppimport(%s) traceback' % (repr(name))", " print '-'*50", " print '\\n'.join(blocks)", " print '='*50", "", " #a = getattr(a,b[-1],ppimport('.'.join(b)))", " return _old_inspect_getfile(ppresolve(object))" ] } } ] }, { "hash": "afa86a9a82bce5f6d87bb19276a1f140cc1129ae", "msg": "Fixed help for postponed attributes. Added docs to overwritten methods/functions.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-11T19:42:43+00:00", "author_timezone": 0, "committer_date": "2004-05-11T19:42:43+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d7b3cd5daa9dac6e8e69ca69c27fd8d5e4041d73" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 4, "insertions": 29, "lines": 33, "files": 2, "dmm_unit_size": 0.7142857142857143, "dmm_unit_complexity": 0.7142857142857143, "dmm_unit_interfacing": 0.8571428571428571, "modified_files": [ { "old_path": "scipy_base/__init__.py", "new_path": "scipy_base/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -27,6 +27,8 @@\n from shape_base import *\n from matrix_base import *\n \n+\n+\n from polynomial import *\n from scimath import *\n from machar import *\n@@ -40,3 +42,7 @@\n \n from scipy_test.testing import ScipyTest\n test = ScipyTest('scipy_base').test\n+\n+if _sys.modules.has_key('scipy_base.Matrix') \\\n+ and _sys.modules['scipy_base.Matrix'] is None:\n+ del _sys.modules['scipy_base.Matrix']\n", "added_lines": 6, "deleted_lines": 0, "source_code": "\nfrom info_scipy_base import __doc__\nfrom scipy_base_version import scipy_base_version as __version__\n\nfrom ppimport import ppimport, ppimport_attr\n\n# The following statement is equivalent to\n#\n# from Matrix import Matrix as mat\n#\n# but avoids expensive LinearAlgebra import when\n# Matrix is not used.\nmat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n\n# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.\nimport fastumath # no need to use scipy_base.fastumath\nimport sys as _sys\n_sys.modules['umath'] = fastumath\n\nimport Numeric\nfrom Numeric import *\n\nimport limits\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\n\n\nfrom polynomial import *\nfrom scimath import *\nfrom machar import *\nfrom pexec import *\n\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n\nfrom scipy_test.testing import ScipyTest\ntest = ScipyTest('scipy_base').test\n\nif _sys.modules.has_key('scipy_base.Matrix') \\\n and _sys.modules['scipy_base.Matrix'] is None:\n del _sys.modules['scipy_base.Matrix']\n", "source_code_before": "\nfrom info_scipy_base import __doc__\nfrom scipy_base_version import scipy_base_version as __version__\n\nfrom ppimport import ppimport, ppimport_attr\n\n# The following statement is equivalent to\n#\n# from Matrix import Matrix as mat\n#\n# but avoids expensive LinearAlgebra import when\n# Matrix is not used.\nmat = ppimport_attr(ppimport('Matrix'), 'Matrix')\n\n# Force Numeric to use scipy_base.fastumath instead of Numeric.umath.\nimport fastumath # no need to use scipy_base.fastumath\nimport sys as _sys\n_sys.modules['umath'] = fastumath\n\nimport Numeric\nfrom Numeric import *\n\nimport limits\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\nfrom polynomial import *\nfrom scimath import *\nfrom machar import *\nfrom pexec import *\n\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF/fastumath.PINF\n\nfrom scipy_test.testing import ScipyTest\ntest = ScipyTest('scipy_base').test\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 29, "complexity": 0, "token_count": 160, "diff_parsed": { "added": [ "", "", "", "if _sys.modules.has_key('scipy_base.Matrix') \\", " and _sys.modules['scipy_base.Matrix'] is None:", " del _sys.modules['scipy_base.Matrix']" ], "deleted": [] } }, { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -86,8 +86,12 @@ def _ppimport_attr_getter(self):\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n+\n return attr\n \n+ def __nonzero__(self):\n+ return 1\n+\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n@@ -161,7 +165,7 @@ def ppimport(name):\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n- \n+\n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n@@ -183,6 +187,7 @@ def ppimport(name):\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n+\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n@@ -344,7 +349,11 @@ def ppresolve(a,ignore_failure=None):\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n- return '.'.join(ns+b)\n+ a = '.'.join(ns+b)\n+ b = '.'.join(b)\n+ if sys.modules.has_key(b) and sys.modules[b] is None:\n+ del sys.modules[b]\n+ return a\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n@@ -368,6 +377,7 @@ def _ppresolve_ignore_failure(a):\n \n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n+ _old_pydoc_help_call.__doc__\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n@@ -376,6 +386,7 @@ def _scipy_pydoc_help_call(self,*args,**kwds):\n \n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n+ _old_pydoc_Doc_document.__doc__\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n@@ -384,14 +395,22 @@ def _scipy_pydoc_Doc_document(self,*args,**kwds):\n \n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n- return _old_pydoc_describe(ppresolve(object))\n+ _old_pydoc_describe.__doc__\n+ return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _pydoc.describe = _scipy_pydoc_describe\n \n+ _old_pydoc_locate = _pydoc.locate\n+ def _scipy_pydoc_locate(thing, forceload=0):\n+ _old_pydoc_locate.__doc__\n+ return _old_pydoc_locate(_ppresolve_ignore_failure(thing),\n+ forceload=forceload)\n+ _pydoc.locate = _scipy_pydoc_locate\n+\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n+ _old_inspect_getfile.__doc__\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n-\n", "added_lines": 23, "deleted_lines": 4, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n\n return attr\n\n def __nonzero__(self):\n return 1\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n\n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n a = '.'.join(ns+b)\n b = '.'.join(b)\n if sys.modules.has_key(b) and sys.modules[b] is None:\n del sys.modules[b]\n return a\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n _old_pydoc_help_call.__doc__\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n _old_pydoc_Doc_document.__doc__\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n _old_pydoc_describe.__doc__\n return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n _old_pydoc_locate = _pydoc.locate\n def _scipy_pydoc_locate(thing, forceload=0):\n _old_pydoc_locate.__doc__\n return _old_pydoc_locate(_ppresolve_ignore_failure(thing),\n forceload=forceload)\n _pydoc.locate = _scipy_pydoc_locate\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n _old_inspect_getfile.__doc__\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n return attr\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n \n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n return '.'.join(ns+b)\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(ppresolve(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__nonzero__", "long_name": "__nonzero__( self )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 92, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 95, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 114, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 119, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 127, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 204, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 223, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 238, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 252, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 292, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 299, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 33, "complexity": 14, "token_count": 234, "parameters": [ "a", "ignore_failure" ], "start_line": 325, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self", "args", "kwds" ], "start_line": 388, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "object" ], "start_line": 397, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_locate", "long_name": "_scipy_pydoc_locate( thing , forceload = 0 )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "thing", "forceload" ], "start_line": 403, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "object" ], "start_line": 411, "end_line": 415, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 100, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 115, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 123, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 199, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 218, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 233, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 247, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 294, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 301, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 29, "complexity": 12, "token_count": 197, "parameters": [ "a", "ignore_failure" ], "start_line": 320, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 356, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "args", "kwds" ], "start_line": 370, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 40, "parameters": [ "self", "args", "kwds" ], "start_line": 378, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "object" ], "start_line": 386, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "object" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "_scipy_pydoc_locate", "long_name": "_scipy_pydoc_locate( thing , forceload = 0 )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "thing", "forceload" ], "start_line": 403, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__nonzero__", "long_name": "__nonzero__( self )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 92, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 33, "complexity": 14, "token_count": 234, "parameters": [ "a", "ignore_failure" ], "start_line": 325, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self", "args", "kwds" ], "start_line": 388, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "object" ], "start_line": 397, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "object" ], "start_line": 411, "end_line": 415, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 127, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 } ], "nloc": 317, "complexity": 90, "token_count": 1951, "diff_parsed": { "added": [ "", " def __nonzero__(self):", " return 1", "", "", "", " a = '.'.join(ns+b)", " b = '.'.join(b)", " if sys.modules.has_key(b) and sys.modules[b] is None:", " del sys.modules[b]", " return a", " _old_pydoc_help_call.__doc__", " _old_pydoc_Doc_document.__doc__", " _old_pydoc_describe.__doc__", " return _old_pydoc_describe(_ppresolve_ignore_failure(object))", " _old_pydoc_locate = _pydoc.locate", " def _scipy_pydoc_locate(thing, forceload=0):", " _old_pydoc_locate.__doc__", " return _old_pydoc_locate(_ppresolve_ignore_failure(thing),", " forceload=forceload)", " _pydoc.locate = _scipy_pydoc_locate", "", " _old_inspect_getfile.__doc__" ], "deleted": [ "", " return '.'.join(ns+b)", " return _old_pydoc_describe(ppresolve(object))", "" ] } } ] }, { "hash": "77253fbc2388d981c57cdbb9e46f47bceeb554a7", "msg": "Few typical setup.py example scripts.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-12T14:07:55+00:00", "author_timezone": 0, "committer_date": "2004-05-12T14:07:55+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "afa86a9a82bce5f6d87bb19276a1f140cc1129ae" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 0, "insertions": 60, "lines": 60, "files": 3, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": null, "new_path": "scipy_distutils/examples/setup_module_pure.py", "filename": "setup_module_pure.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,11 @@\n+#!/usr/bin/env python\n+from scipy_distutils.core import setup\n+from scipy_distutils.misc_util import default_config_dict\n+\n+def configuration(parent_package='',parent_path=None):\n+ package_name = 'module'\n+ config = default_config_dict(package_name, parent_package)\n+ return config\n+\n+if __name__ == '__main__':\n+ setup(**configuration(parent_path=''))\n", "added_lines": 11, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "source_code_before": null, "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "parent_package", "parent_path" ], "start_line": 5, "end_line": 8, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "parent_package", "parent_path" ], "start_line": 5, "end_line": 8, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "nloc": 8, "complexity": 1, "token_count": 52, "diff_parsed": { "added": [ "#!/usr/bin/env python", "from scipy_distutils.core import setup", "from scipy_distutils.misc_util import default_config_dict", "", "def configuration(parent_package='',parent_path=None):", " package_name = 'module'", " config = default_config_dict(package_name, parent_package)", " return config", "", "if __name__ == '__main__':", " setup(**configuration(parent_path=''))" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_distutils/examples/setup_module_pure_data.py", "filename": "setup_module_pure_data.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,23 @@\n+#!/usr/bin/env python\n+from os.path import join\n+from glob import glob\n+from scipy_distutils.core import setup\n+from scipy_distutils.misc_util import default_config_dict, get_path\n+\n+def configuration(parent_package='',parent_path=None):\n+ package_name = 'module'\n+ config = default_config_dict(package_name, parent_package)\n+\n+ local_path = get_path(__name__,parent_path)\n+ install_path = join(*config['name'].split('.'))\n+\n+ config['data_files'].append((install_path,\n+ [join(local_path,'images.zip')]))\n+\n+ config['data_files'].append((join(install_path,'images'),\n+ glob(join(local_path,'images','*.png'))))\n+\n+ return config\n+\n+if __name__ == '__main__':\n+ setup(**configuration(parent_path=''))\n", "added_lines": 23, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\nfrom os.path import join\nfrom glob import glob\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict, get_path\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n\n local_path = get_path(__name__,parent_path)\n install_path = join(*config['name'].split('.'))\n\n config['data_files'].append((install_path,\n [join(local_path,'images.zip')]))\n\n config['data_files'].append((join(install_path,'images'),\n glob(join(local_path,'images','*.png'))))\n\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "source_code_before": null, "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure_data.py", "nloc": 10, "complexity": 1, "token_count": 95, "parameters": [ "parent_package", "parent_path" ], "start_line": 7, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure_data.py", "nloc": 10, "complexity": 1, "token_count": 95, "parameters": [ "parent_package", "parent_path" ], "start_line": 7, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 } ], "nloc": 16, "complexity": 1, "token_count": 135, "diff_parsed": { "added": [ "#!/usr/bin/env python", "from os.path import join", "from glob import glob", "from scipy_distutils.core import setup", "from scipy_distutils.misc_util import default_config_dict, get_path", "", "def configuration(parent_package='',parent_path=None):", " package_name = 'module'", " config = default_config_dict(package_name, parent_package)", "", " local_path = get_path(__name__,parent_path)", " install_path = join(*config['name'].split('.'))", "", " config['data_files'].append((install_path,", " [join(local_path,'images.zip')]))", "", " config['data_files'].append((join(install_path,'images'),", " glob(join(local_path,'images','*.png'))))", "", " return config", "", "if __name__ == '__main__':", " setup(**configuration(parent_path=''))" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_distutils/examples/setup_module_pure_super.py", "filename": "setup_module_pure_super.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,26 @@\n+#!/usr/bin/env python\n+from scipy_distutils.core import setup\n+from scipy_distutils.misc_util import default_config_dict, get_path, \\\n+ merge_config_dicts, get_subpackages\n+\n+def configuration(parent_package='',parent_path=None):\n+ package_name = 'module'\n+ config = default_config_dict(package_name, parent_package)\n+\n+ local_path = get_path(__name__,parent_path)\n+ install_path = join(*config['name'].split('.'))\n+\n+ config_list = [config]\n+\n+ config_list += get_subpackages(local_path,\n+ parent=config['name'],\n+ parent_path=parent_path,\n+ include_packages = ['subpackage1','subpackage2']\n+ )\n+\n+ config = merge_config_dicts(config_list)\n+\n+ return config\n+\n+if __name__ == '__main__':\n+ setup(**configuration(parent_path=''))\n", "added_lines": 26, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict, get_path, \\\n merge_config_dicts, get_subpackages\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n\n local_path = get_path(__name__,parent_path)\n install_path = join(*config['name'].split('.'))\n\n config_list = [config]\n\n config_list += get_subpackages(local_path,\n parent=config['name'],\n parent_path=parent_path,\n include_packages = ['subpackage1','subpackage2']\n )\n\n config = merge_config_dicts(config_list)\n\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "source_code_before": null, "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure_super.py", "nloc": 13, "complexity": 1, "token_count": 83, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure_super.py", "nloc": 13, "complexity": 1, "token_count": 83, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 } ], "nloc": 18, "complexity": 1, "token_count": 118, "diff_parsed": { "added": [ "#!/usr/bin/env python", "from scipy_distutils.core import setup", "from scipy_distutils.misc_util import default_config_dict, get_path, \\", " merge_config_dicts, get_subpackages", "", "def configuration(parent_package='',parent_path=None):", " package_name = 'module'", " config = default_config_dict(package_name, parent_package)", "", " local_path = get_path(__name__,parent_path)", " install_path = join(*config['name'].split('.'))", "", " config_list = [config]", "", " config_list += get_subpackages(local_path,", " parent=config['name'],", " parent_path=parent_path,", " include_packages = ['subpackage1','subpackage2']", " )", "", " config = merge_config_dicts(config_list)", "", " return config", "", "if __name__ == '__main__':", " setup(**configuration(parent_path=''))" ], "deleted": [] } } ] }, { "hash": "ebe4943bab7d6092e9028a72a0482f887a530604", "msg": "No need to wrap pydoc.locate. Fixes interactive help() session.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-12T20:56:41+00:00", "author_timezone": 0, "committer_date": "2004-05-12T20:56:41+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "77253fbc2388d981c57cdbb9e46f47bceeb554a7" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 7, "insertions": 0, "lines": 7, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_base/ppimport.py", "new_path": "scipy_base/ppimport.py", "filename": "ppimport.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -399,13 +399,6 @@ def _scipy_pydoc_describe(object):\n return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _pydoc.describe = _scipy_pydoc_describe\n \n- _old_pydoc_locate = _pydoc.locate\n- def _scipy_pydoc_locate(thing, forceload=0):\n- _old_pydoc_locate.__doc__\n- return _old_pydoc_locate(_ppresolve_ignore_failure(thing),\n- forceload=forceload)\n- _pydoc.locate = _scipy_pydoc_locate\n-\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n", "added_lines": 0, "deleted_lines": 7, "source_code": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n\n return attr\n\n def __nonzero__(self):\n return 1\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n\n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n a = '.'.join(ns+b)\n b = '.'.join(b)\n if sys.modules.has_key(b) and sys.modules[b] is None:\n del sys.modules[b]\n return a\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n _old_pydoc_help_call.__doc__\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n _old_pydoc_Doc_document.__doc__\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n _old_pydoc_describe.__doc__\n return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n _old_inspect_getfile.__doc__\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nPostpone module import to future.\n\nPython versions: 1.5.2 - 2.3.x\nAuthor: Pearu Peterson \nCreated: March 2003\n$Revision$\n$Date$\n\"\"\"\n__all__ = ['ppimport','ppimport_attr','ppresolve']\n\nimport os\nimport sys\nimport string\nimport types\nimport traceback\n\nDEBUG=0\n\n_ppimport_is_enabled = 1\ndef enable():\n \"\"\" Enable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 1\n\ndef disable():\n \"\"\" Disable postponed importing.\"\"\"\n global _ppimport_is_enabled\n _ppimport_is_enabled = 0\n\nclass PPImportError(ImportError):\n pass\n\ndef _get_so_ext(_cache={}):\n so_ext = _cache.get('so_ext')\n if so_ext is None:\n if sys.platform[:5]=='linux':\n so_ext = '.so'\n else:\n try:\n # if possible, avoid expensive get_config_vars call\n from distutils.sysconfig import get_config_vars\n so_ext = get_config_vars('SO')[0] or ''\n except ImportError:\n #XXX: implement hooks for .sl, .dll to fully support\n # Python 1.5.x \n so_ext = '.so'\n _cache['so_ext'] = so_ext\n return so_ext\n\ndef _get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n # Python<=2.0 support\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef ppimport_attr(module, name):\n \"\"\" ppimport(module, name) is 'postponed' getattr(module, name)\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled and isinstance(module, _ModuleLoader):\n return _AttrLoader(module, name)\n return getattr(module, name)\n\nclass _AttrLoader:\n def __init__(self, module, name):\n self.__dict__['_ppimport_attr_module'] = module\n self.__dict__['_ppimport_attr_name'] = name\n\n def _ppimport_attr_getter(self):\n module = self.__dict__['_ppimport_attr_module']\n if isinstance(module, _ModuleLoader):\n # in case pp module was loaded by other means\n module = sys.modules[module.__name__]\n attr = getattr(module,\n self.__dict__['_ppimport_attr_name'])\n try:\n d = attr.__dict__\n if d is not None:\n self.__dict__ = d\n except AttributeError:\n pass\n self.__dict__['_ppimport_attr'] = attr\n\n return attr\n\n def __nonzero__(self):\n return 1\n\n def __getattr__(self, name):\n try:\n attr = self.__dict__['_ppimport_attr']\n except KeyError:\n attr = self._ppimport_attr_getter()\n if name=='_ppimport_attr':\n return attr\n return getattr(attr, name)\n\n def __repr__(self):\n if self.__dict__.has_key('_ppimport_attr'):\n return repr(self._ppimport_attr)\n module = self.__dict__['_ppimport_attr_module']\n name = self.__dict__['_ppimport_attr_name']\n return \"\" % (`name`,`module`)\n\n __str__ = __repr__\n\n # For function and class attributes.\n def __call__(self, *args, **kwds):\n return self._ppimport_attr(*args,**kwds)\n\n\n\ndef _is_local_module(p_dir,name,suffices):\n base = os.path.join(p_dir,name)\n for suffix in suffices:\n if os.path.isfile(base+suffix):\n if p_dir:\n return base+suffix\n return name+suffix\n\ndef ppimport(name):\n \"\"\" ppimport(name) -> module or module wrapper\n\n If name has been imported before, return module. Otherwise\n return ModuleLoader instance that transparently postpones\n module import until the first attempt to access module name\n attributes.\n \"\"\"\n global _ppimport_is_enabled\n\n level = 1\n parent_frame = p_frame = _get_frame(level)\n while not p_frame.f_locals.has_key('__name__'):\n level = level + 1\n p_frame = _get_frame(level)\n\n p_name = p_frame.f_locals['__name__']\n if p_name=='__main__':\n p_dir = ''\n fullname = name\n elif p_frame.f_locals.has_key('__path__'):\n # python package\n p_path = p_frame.f_locals['__path__']\n p_dir = p_path[0]\n fullname = p_name + '.' + name\n else:\n # python module\n p_file = p_frame.f_locals['__file__']\n p_dir = os.path.dirname(p_file)\n fullname = p_name + '.' + name\n\n # module may be imported already\n module = sys.modules.get(fullname)\n if module is not None:\n if _ppimport_is_enabled or isinstance(module, types.ModuleType):\n return module\n return module._ppimport_importer()\n\n so_ext = _get_so_ext()\n py_exts = ('.py','.pyc','.pyo')\n so_exts = (so_ext,'module'+so_ext)\n\n for d,n,fn,e in [\\\n # name is local python module or local extension module\n (p_dir, name, fullname, py_exts+so_exts),\n # name is local package\n (os.path.join(p_dir, name), '__init__', fullname, py_exts),\n # name is package in parent directory (scipy specific)\n (os.path.join(os.path.dirname(p_dir), name), '__init__', name, py_exts),\n ]:\n location = _is_local_module(d, n, e)\n if location is not None:\n fullname = fn\n break\n\n if location is None:\n # name is to be looked in python sys.path.\n fullname = name\n location = 'sys.path'\n\n # Try once more if module is imported.\n # This covers the case when importing from python module\n module = sys.modules.get(fullname)\n\n if module is not None:\n if _ppimport_is_enabled or isinstance(module,types.ModuleType):\n return module\n return module._ppimport_importer()\n # It is OK if name does not exists. The ImportError is\n # postponed until trying to use the module.\n\n loader = _ModuleLoader(fullname,location,p_frame=parent_frame)\n if _ppimport_is_enabled:\n return loader\n\n return loader._ppimport_importer()\n\ndef _get_frame_code(frame):\n filename = frame.f_code.co_filename\n lineno = frame.f_lineno\n result = '%s in %s:\\n' % (filename,frame.f_code.co_name)\n if not os.path.isfile(filename):\n return result\n f = open(filename)\n i = 1\n line = f.readline()\n while line:\n line = f.readline()\n i = i + 1\n if (abs(i-lineno)<2):\n result += '#%d: %s\\n' % (i,line.rstrip())\n if i>lineno+3:\n break\n f.close()\n return result\n\ndef frame_traceback(frame):\n if not frame:\n return\n blocks = []\n f = frame\n while f:\n blocks.insert(0,_get_frame_code(f))\n f = f.f_back\n print '='*50\n print '\\n'.join(blocks)\n print '='*50 \n\nclass _ModuleLoader:\n # Don't use it directly. Use ppimport instead.\n\n def __init__(self,name,location,p_frame=None):\n\n # set attributes, avoid calling __setattr__\n self.__dict__['__name__'] = name\n self.__dict__['__file__'] = location\n self.__dict__['_ppimport_p_frame'] = p_frame\n\n if location != 'sys.path':\n from scipy_test.testing import ScipyTest\n self.__dict__['test'] = ScipyTest(self).test\n\n # install loader\n sys.modules[name] = self\n\n def _ppimport_importer(self):\n name = self.__name__\n\n try:\n module = sys.modules[name]\n\texcept KeyError:\n raise ImportError,self.__dict__.get('_ppimport_exc_info')[1]\n if module is not self:\n exc_info = self.__dict__.get('_ppimport_exc_info')\n if exc_info is not None:\n raise PPImportError,\\\n ''.join(traceback.format_exception(*exc_info))\n else:\n assert module is self,`(module, self)`\n\n # uninstall loader\n del sys.modules[name]\n\n if DEBUG:\n print 'Executing postponed import for %s' %(name)\n try:\n module = __import__(name,None,None,['*'])\n except Exception,msg: # ImportError:\n if DEBUG:\n p_frame = self.__dict__.get('_ppimport_p_frame',None)\n frame_traceback(p_frame)\n self.__dict__['_ppimport_exc_info'] = sys.exc_info()\n raise\n\n assert isinstance(module,types.ModuleType),`module`\n\n self.__dict__ = module.__dict__\n self.__dict__['_ppimport_module'] = module\n\n # XXX: Should we check the existence of module.test? Warn?\n from scipy_test.testing import ScipyTest\n module.test = ScipyTest(module).test\n\n return module\n\n def __setattr__(self, name, value):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return setattr(module, name, value)\n\n def __getattr__(self, name):\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return getattr(module, name)\n\n def __repr__(self):\n global _ppimport_is_enabled\n if not _ppimport_is_enabled:\n try:\n module = self.__dict__['_ppimport_module']\n except KeyError:\n module = self._ppimport_importer()\n return module.__repr__()\n if self.__dict__.has_key('_ppimport_module'):\n status = 'imported'\n elif self.__dict__.has_key('_ppimport_exc_info'):\n status = 'import error'\n else:\n status = 'import postponed'\n return '' \\\n % (`self.__name__`,`self.__file__`, status)\n\n __str__ = __repr__\n\ndef ppresolve(a,ignore_failure=None):\n \"\"\" Return resolved object a.\n\n a can be module name, postponed module, postponed modules\n attribute, string representing module attribute, or any\n Python object.\n \"\"\"\n global _ppimport_is_enabled\n if _ppimport_is_enabled:\n disable()\n a = ppresolve(a,ignore_failure=ignore_failure)\n enable()\n return a\n if type(a) is type(''):\n ns = a.split('.')\n a = ppimport(ns[0])\n b = [ns[0]]\n del ns[0]\n while ns:\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n b.append(ns[0])\n del ns[0]\n if ignore_failure and not hasattr(a, b[-1]):\n a = '.'.join(ns+b)\n b = '.'.join(b)\n if sys.modules.has_key(b) and sys.modules[b] is None:\n del sys.modules[b]\n return a\n a = getattr(a,b[-1])\n if hasattr(a,'_ppimport_importer') or \\\n hasattr(a,'_ppimport_module'):\n a = a._ppimport_module\n if hasattr(a,'_ppimport_attr'):\n a = a._ppimport_attr\n return a\n\ndef _ppresolve_ignore_failure(a):\n return ppresolve(a,ignore_failure=1)\n\ntry:\n import pydoc as _pydoc\nexcept ImportError:\n _pydoc = None\n\nif _pydoc is not None:\n # Redefine __call__ method of help.__class__ to\n # support ppimport.\n import new as _new\n\n _old_pydoc_help_call = _pydoc.help.__class__.__call__\n def _scipy_pydoc_help_call(self,*args,**kwds):\n _old_pydoc_help_call.__doc__\n return _old_pydoc_help_call(self, *map(_ppresolve_ignore_failure,args),\n **kwds)\n _pydoc.help.__class__.__call__ = _new.instancemethod(_scipy_pydoc_help_call,\n None,\n _pydoc.help.__class__)\n\n _old_pydoc_Doc_document = _pydoc.Doc.document\n def _scipy_pydoc_Doc_document(self,*args,**kwds):\n _old_pydoc_Doc_document.__doc__\n args = (_ppresolve_ignore_failure(args[0]),) + args[1:]\n return _old_pydoc_Doc_document(self,*args,**kwds)\n _pydoc.Doc.document = _new.instancemethod(_scipy_pydoc_Doc_document,\n None,\n _pydoc.Doc)\n\n _old_pydoc_describe = _pydoc.describe\n def _scipy_pydoc_describe(object):\n _old_pydoc_describe.__doc__\n return _old_pydoc_describe(_ppresolve_ignore_failure(object))\n _pydoc.describe = _scipy_pydoc_describe\n\n _old_pydoc_locate = _pydoc.locate\n def _scipy_pydoc_locate(thing, forceload=0):\n _old_pydoc_locate.__doc__\n return _old_pydoc_locate(_ppresolve_ignore_failure(thing),\n forceload=forceload)\n _pydoc.locate = _scipy_pydoc_locate\n\n import inspect as _inspect\n _old_inspect_getfile = _inspect.getfile\n def _scipy_inspect_getfile(object):\n _old_inspect_getfile.__doc__\n if isinstance(object,_ModuleLoader):\n return object.__dict__['__file__']\n return _old_inspect_getfile(object)\n _inspect.getfile = _scipy_inspect_getfile\n", "methods": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__nonzero__", "long_name": "__nonzero__( self )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 92, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 95, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 114, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 119, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 127, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 204, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 223, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 238, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 252, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 292, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 299, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 33, "complexity": 14, "token_count": 234, "parameters": [ "a", "ignore_failure" ], "start_line": 325, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self", "args", "kwds" ], "start_line": 388, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "object" ], "start_line": 397, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "object" ], "start_line": 404, "end_line": 408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [ { "name": "enable", "long_name": "enable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 22, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 27, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_get_so_ext", "long_name": "_get_so_ext( _cache = { } )", "filename": "ppimport.py", "nloc": 13, "complexity": 5, "token_count": 70, "parameters": [ "_cache" ], "start_line": 35, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "_get_frame", "long_name": "_get_frame( level = 0 )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 52, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ppimport_attr", "long_name": "ppimport_attr( module , name )", "filename": "ppimport.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "module", "name" ], "start_line": 62, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , module , name )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "module", "name" ], "start_line": 71, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_ppimport_attr_getter", "long_name": "_ppimport_attr_getter( self )", "filename": "ppimport.py", "nloc": 14, "complexity": 4, "token_count": 76, "parameters": [ "self" ], "start_line": 75, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__nonzero__", "long_name": "__nonzero__( self )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 92, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "self", "name" ], "start_line": 95, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self", "args", "kwds" ], "start_line": 114, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_is_local_module", "long_name": "_is_local_module( p_dir , name , suffices )", "filename": "ppimport.py", "nloc": 7, "complexity": 4, "token_count": 49, "parameters": [ "p_dir", "name", "suffices" ], "start_line": 119, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "ppimport", "long_name": "ppimport( name )", "filename": "ppimport.py", "nloc": 49, "complexity": 14, "token_count": 337, "parameters": [ "name" ], "start_line": 127, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "_get_frame_code", "long_name": "_get_frame_code( frame )", "filename": "ppimport.py", "nloc": 18, "complexity": 5, "token_count": 114, "parameters": [ "frame" ], "start_line": 204, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "frame_traceback", "long_name": "frame_traceback( frame )", "filename": "ppimport.py", "nloc": 11, "complexity": 3, "token_count": 51, "parameters": [ "frame" ], "start_line": 223, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , location , p_frame = None )", "filename": "ppimport.py", "nloc": 8, "complexity": 2, "token_count": 69, "parameters": [ "self", "name", "location", "p_frame" ], "start_line": 238, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "_ppimport_importer", "long_name": "_ppimport_importer( self )", "filename": "ppimport.py", "nloc": 30, "complexity": 7, "token_count": 204, "parameters": [ "self" ], "start_line": 252, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "__setattr__", "long_name": "__setattr__( self , name , value )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 292, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "ppimport.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "name" ], "start_line": 299, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "ppimport.py", "nloc": 16, "complexity": 5, "token_count": 87, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "ppresolve", "long_name": "ppresolve( a , ignore_failure = None )", "filename": "ppimport.py", "nloc": 33, "complexity": 14, "token_count": 234, "parameters": [ "a", "ignore_failure" ], "start_line": 325, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "_ppresolve_ignore_failure", "long_name": "_ppresolve_ignore_failure( a )", "filename": "ppimport.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "a" ], "start_line": 365, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "_scipy_pydoc_help_call", "long_name": "_scipy_pydoc_help_call( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "args", "kwds" ], "start_line": 379, "end_line": 382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_Doc_document", "long_name": "_scipy_pydoc_Doc_document( self , * args , ** kwds )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self", "args", "kwds" ], "start_line": 388, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_describe", "long_name": "_scipy_pydoc_describe( object )", "filename": "ppimport.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "object" ], "start_line": 397, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_scipy_pydoc_locate", "long_name": "_scipy_pydoc_locate( thing , forceload = 0 )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "thing", "forceload" ], "start_line": 403, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "_scipy_inspect_getfile", "long_name": "_scipy_inspect_getfile( object )", "filename": "ppimport.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "object" ], "start_line": 411, "end_line": 415, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "_scipy_pydoc_locate", "long_name": "_scipy_pydoc_locate( thing , forceload = 0 )", "filename": "ppimport.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "thing", "forceload" ], "start_line": 403, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "nloc": 311, "complexity": 89, "token_count": 1916, "diff_parsed": { "added": [], "deleted": [ " _old_pydoc_locate = _pydoc.locate", " def _scipy_pydoc_locate(thing, forceload=0):", " _old_pydoc_locate.__doc__", " return _old_pydoc_locate(_ppresolve_ignore_failure(thing),", " forceload=forceload)", " _pydoc.locate = _scipy_pydoc_locate", "" ] } } ] }, { "hash": "03693fb5fa4343165c0f3eeef4d769932a07dc3e", "msg": "Handle the case where .svn/entries does not exist.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-13T08:39:59+00:00", "author_timezone": 0, "committer_date": "2004-05-13T08:39:59+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "ebe4943bab7d6092e9028a72a0482f887a530604" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 1, "insertions": 5, "lines": 6, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -558,8 +558,12 @@ def generate_svn_version_py(extension, build_dir):\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n- if not dep_util.newer(entries, target):\n+ if os.path.isfile(entries):\n+ if not dep_util.newer(entries, target):\n+ return target\n+ elif os.path.isfile(target):\n return target\n+\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n", "added_lines": 5, "deleted_lines": 1, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_build_platlib():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','lib'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_build_platlib():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','lib'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if not dep_util.newer(entries, target):\n return target\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "get_build_platlib", "long_name": "get_build_platlib( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 250, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 264, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 277, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 279, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 291, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 300, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 304, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 306, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 316, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 334, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 341, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 348, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 355, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 377, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 397, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 408, "end_line": 504, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 506, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 109, "parameters": [ "extension", "build_dir" ], "start_line": 544, "end_line": 571, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 573, "end_line": 584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "get_build_platlib", "long_name": "get_build_platlib( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 250, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 264, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 277, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 279, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 291, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 300, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 304, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 306, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 316, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 334, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 341, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 348, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 355, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 377, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 397, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 408, "end_line": 504, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 506, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 12, "complexity": 2, "token_count": 87, "parameters": [ "extension", "build_dir" ], "start_line": 544, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 569, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 109, "parameters": [ "extension", "build_dir" ], "start_line": 544, "end_line": 571, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 } ], "nloc": 425, "complexity": 136, "token_count": 3090, "diff_parsed": { "added": [ " if os.path.isfile(entries):", " if not dep_util.newer(entries, target):", " return target", " elif os.path.isfile(target):", "" ], "deleted": [ " if not dep_util.newer(entries, target):" ] } } ] }, { "hash": "b7cc0ff045f99119e08a54aab09abc54487384ee", "msg": "Added proc.py.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-13T08:59:08+00:00", "author_timezone": 0, "committer_date": "2004-05-13T08:59:08+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "03693fb5fa4343165c0f3eeef4d769932a07dc3e" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 0, "insertions": 494, "lines": 494, "files": 1, "dmm_unit_size": 0.6784660766961652, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 0.887905604719764, "modified_files": [ { "old_path": null, "new_path": "scipy_distutils/proc.py", "filename": "proc.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,494 @@\n+#! /usr/bin/python\n+# Currently only implemented for linux...need to do win32\n+# I thought of making OS specific modules that were chosen \n+# based on OS much like path works, but I think this will\n+# break pickling when process objects are passed between\n+# two OSes because the module name is saved in the pickle.\n+# A Unix process info object passed to a Windows machine\n+# would attempt to import the linux proc module and fail.\n+# Using a single module with if-then-else I think prevents\n+# this name problem (but it isn't as pretty...)\n+\n+import sys,string\n+\n+if string.find(sys.platform,'linux') != -1:\n+ # begin linux specific\n+ import string,os,stat\n+ import pwd, grp\n+ \n+ hertz = 100. #standard value for jiffies (in seconds) on Linux.\n+ states = {'R':'RUNNING','S':'SLEEPING','Z':'ZOMBIE',\n+ 'T':'TRACED','D':'DEEPSLEEP'}\n+ \n+ import socket\n+ long_machine_name = socket.gethostname()\n+ machine_name = string.split(long_machine_name,'.')[0]\n+ \n+ def uptime_info():\n+ f = open(\"/proc/uptime\")\n+ line = f.readline()\n+ field = string.split(line) \n+ info={}\n+ info['uptime'] = eval(field[0])\n+ info['idle'] = eval(field[1])\n+ return info\n+ \n+ def cpu_info():\n+ \"\"\"* We'll assume SMP machines have identical processors\n+ \n+ *\"\"\"\n+ f = open(\"/proc/cpuinfo\")\n+ lines = f.readlines()\n+ pairs = map(lambda x,y=':':string.split(x,y),lines)\n+ info={}\n+ for line in pairs:\n+ if len(line) > 1: \n+ key = string.strip(line[0])\n+ value = string.strip(line[1])\n+ try: \n+ info[key] = eval(value)\n+ except: \n+ info[key] = value\n+ sub_info = {}\n+ sub_info['cpu_count'] = info['processor'] + 1\n+ sub_info['cpu_type'] = filter_name(info['model name'])\n+ sub_info['cpu_cache'] = eval(string.split(info['cache size'])[0])\n+ sub_info['cpu_speed'] = round(info['cpu MHz']/1000.,1) # in GHz\n+ sub_info['cpu_bogomips'] = info['bogomips'] \n+ #print sub_info \n+ return sub_info\n+ \n+ def filter_name(name):\n+ \"\"\"* Try to shorten the verbose names in cpuinfo *\"\"\"\n+ if string.find(name,'Pentium III') != -1:\n+ return 'P3'\n+ elif string.find(name,'Athlon') != -1:\n+ return 'Athlon'\n+ elif string.find(name,'Pentium II') != -1:\n+ return 'P2'\n+ return name\n+ \n+ \n+ def mem_info():\n+ f = open(\"/proc/meminfo\")\n+ l = f.readlines()\n+ x = string.split(l[1])\n+ total = eval(x[1])\n+ used = eval(x[2])\n+ free = eval(x[3])\n+ shared = eval(x[4])\n+ buffers = eval(x[5])\n+ cached = eval(x[6])\n+ \n+ x = string.split(l[2])\n+ stotal = eval(x[1])\n+ sused = eval(x[2])\n+ sfree = eval(x[3])\n+ \n+ memtotal = os.stat(\"/proc/kcore\")[stat.ST_SIZE]\n+ \n+ m = 1024*1024\n+ #print \"Memory RAM : %d MB (%d MB kernel, %d MB free)\" % (memtotal/m, (memtotal-total)/m, free/m)\n+ #print \" usage : %d MB shared %d MB buffers %d MB cached\" % (shared/m, buffers/m, cached/m)\n+ #print \"Swap area : %d MB (%d MB used)\" % (stotal/m, sused/m)\n+ info = {}\n+ info['mem_total'] = memtotal/m\n+ info['mem_kernel'] = (memtotal-total)/m\n+ info['mem_free'] = free/m\n+ info['swap_total'] = stotal/m\n+ info['swap_free'] = (stotal-sused)/m\n+ return info\n+ \n+ def load_avg():\n+ f = open(\"/proc/loadavg\")\n+ line = f.readline()\n+ field = string.split(line) \n+ info={}\n+ info['load_1'] = eval(field[0])\n+ info['load_5'] = eval(field[1])\n+ info['load_15'] = eval(field[2])\n+ return info\n+ \n+ def machine_info():\n+ all = load_avg()\n+ all.update(cpu_info())\n+ all.update(mem_info())\n+ all['long_name'] = long_machine_name\n+ all['name'] = machine_name\n+ return all\n+ \n+ \n+ uid_cache = {}\n+ gid_cache = {}\n+ def user_from_uid(uid):\n+ global uid_cache\n+ try:\n+ user = uid_cache[uid]\n+ except:\n+ user = pwd.getpwuid(uid)[0]\n+ uid_cache[uid] = user\n+ return user \n+ \n+ def group_from_gid(gid):\n+ global gid_cache\n+ try:\n+ group = gid_cache[gid]\n+ except:\n+ group = grp.getgrgid(gid)[0]\n+ gid_cache[gid] =group \n+ return group \n+ \n+ # Yes, this is slow. It also works and is pure Python (easy).\n+ # If your looking to do a real top, or fast ps command use SIWG to wrap the\n+ # ps and top code. This would give much better performance, be more robust,\n+ # and make the generally world a happier place. Please send it in when \n+ # your finished!\n+ # This is all pretty much stolen from readproc.c in the procps \n+ # package (scour the web).\n+ \n+ class process:\n+ def __init__(self,pid,seconds_since_boot=None,total_memory=None):\n+ self.info(int(pid),seconds_since_boot,total_memory)\n+ def info(self,pid,seconds_since_boot=None,total_memory=None):\n+ self.status2proc(pid)\n+ self.stat2proc(pid)\n+ self.statm2proc(pid)\n+ self.get_cmdline(pid)\n+ #self.get_environ(pid)\n+ if self.state == 'Z':\n+ self.cmd = self.cmd + \"\"\n+ self.beautify(seconds_since_boot,total_memory)\n+ self.pid = pid\n+ self.machine = machine_name\n+ self.long_machine = long_machine_name\n+ def status2proc(self,pid):\n+ f = open(\"/proc/%d/status\" % pid)\n+ lines = f.readlines()\n+ #line = map(string.split,lines)\n+ id = map(string.split,lines[4:6])\n+ \n+ #self.cmd = line[0][1]\n+ #self.state = line[1][2]\n+ self.ruid,self.euid,self.suid,self.fuid = map(int,id[0][1:])\n+ self.rgid,self.egid,self.sgid,self.fgid = map(int,id[1][1:])\n+ #self.euid = int(id[0][1])\n+ #self.egid = int(id[1][1])\n+ #self.vm_size = long(line[7][1])\n+ #self.vm_lock = long(line[8][1])\n+ #self.vm_rss = long(line[9][1])\n+ #self.vm_data = long(line[10][1])\n+ #self.vm_stack = long(line[11][1])\n+ #self.vm_exe = long(line[12][1])\n+ #self.vm_lib = long(line[13][1])\n+ \n+ #translate id's to user and group names\n+ #self.ruser = user_from_uid(self.ruid)\n+ #self.suser = user_from_uid(self.suid)\n+ self.euser = user_from_uid(self.euid)\n+ #self.fuser = user_from_uid(self.fuid)\n+ #self.rgroup = group_from_gid(self.rgid)\n+ #self.sgroup = group_from_gid(self.sgid)\n+ self.egroup = group_from_gid(self.egid)\n+ #self.fgroup = group_from_gid(self.fgid)\n+ \n+ def stat2proc(self,pid):\n+ # oh, to have sscanf... (I'm sure it is somewhere)\n+ f = open(\"/proc/%d/stat\" % pid)\n+ s = f.read(-1)\n+ f.close()\n+ cmd = string.rfind(s,'(') + 1\n+ begin = string.rfind(s,')')\n+ self.cmd = s[cmd:begin]\n+ begin = begin + 2\n+ field = string.split(s[begin:])\n+ self.state = field[0]\n+ self.ppid = int(field[1])\n+ #self.pgrp = int(field[2])\n+ #self.session = int(field[3])\n+ self.tty = int(field[4])\n+ #self.tpgid = eval(field[5])\n+ #self.flags = eval(field[6])\n+ #self.min_flt = long(field[7])\n+ #self.cmin_flt = long(field[8])\n+ #self.maj_flt = long(field[9])\n+ #self.cmaj_flt = long(field[10])\n+ self.utime = long(field[11])\n+ self.stime = long(field[12])\n+ self.cutime = int(field[13])\n+ self.cstime = int(field[14])\n+ self.priority = int(field[15])\n+ self.nice = int(field[16])\n+ #self.timeout = eval(field[17])\n+ #self.it_real_value = eval(field[18])\n+ self.start_time = long(field[19])\n+ self.vsize = long(field[20])\n+ self.rss = long(field[21])\n+ self.rss_rlim = long(field[22])\n+ #self.start_code = long(field[23])\n+ #self.end_code = long(field[24])\n+ self.start_stack = long(field[25])\n+ #self.kstk_esp = long(field[26])\n+ #self.kstk_eip = long(field[27])\n+ #self.wchan = long(field[29])\n+ #self.nswap = long(field[30])\n+ self.cnswap = long(field[31])\n+ if self.tty == 0: self.tty=-1\n+ def statm2proc(self,pid):\n+ f = open(\"/proc/%d/statm\" % pid)\n+ s = f.read(-1)\n+ f.close()\n+ field = string.split(s)\n+ self.size = int(field[0])\n+ self.resident = int(field[1])\n+ #self.share = int(field[2])\n+ #self.trs = int(field[3])\n+ #self.lrs = int(field[4])\n+ #self.drs = int(field[5])\n+ #self.dt = int(field[6])\n+ def get_cmdline(self,pid):\n+ f = open(\"/proc/%d/cmdline\" % pid)\n+ self.cmdline = f.read(-1)\n+ f.close() \n+ def get_environ(self,pid):\n+ f = open(\"/proc/%d/environ\" % pid)\n+ self.cmdline = f.read(-1)\n+ f.close()\n+ \n+ def beautify(self,seconds_since_boot=None,total_memory=None):\n+ \"\"\"* total_memory in MB \n+ *\"\"\"\n+ if seconds_since_boot is None:\n+ seconds_since_boot = uptime_info()['uptime']\n+ if total_memory is None:\n+ total_memory = mem_info()['mem_total']\n+ self.beautify_user()\n+ self.beautify_cpu(seconds_since_boot)\n+ self.beautify_memory(total_memory)\n+ self.beautify_state()\n+ def beautify_user(self): \n+ self.uid = self.euid\n+ self.user = self.euser\n+ self.gid = self.egid\n+ self.group = self.egroup\n+ \n+ def beautify_cpu(self,seconds_since_boot):\n+ include_dead_children = 0 \n+ self.total_time = (self.utime + self.stime) / hertz \n+ self.wall_time = seconds_since_boot - self.start_time /hertz\n+ if include_dead_children:\n+ self.total_time = self.total_time + \\\n+ (self.cutime + self.cstime) / hertz\n+ self.pcpu = 0\n+ if self.wall_time:\n+ self.pcpu = self.total_time * 1000. / self.wall_time\n+ if self.pcpu > 999: \n+ self.pcpu = 999.\n+ \n+ self.cpu_percent = self.pcpu / 10.\n+ #foramt time into a days:hours:minutes:seconds string\n+ t = long(self.wall_time)\n+ t,ss = divmod(t,60)\n+ t,mm = divmod(t,60)\n+ t,hh = divmod(t,24)\n+ dd = t\n+ self.wall_time2 = \"%2d:%2d:%2d:%2d\" % (dd,hh,mm,ss)\n+ t = long(self.total_time) \n+ t,ss = divmod(t,60)\n+ t,mm = divmod(t,60)\n+ t,hh = divmod(t,24)\n+ dd = t\n+ self.total_time2 = \"%2d:%2d:%2d:%2d\" % (dd,hh,mm,ss)\n+ \n+ def beautify_memory(self,total_memory):\n+ \"\"\"* translate memory values to MB, and percentage\n+ *\"\"\"\n+ self.total_memory = self.size * 4 / 1024.\n+ self.resident_memory = self.resident * 4/ 1024.\n+ self.memory_percent = self.resident_memory / total_memory * 100\n+ def beautify_state(self):\n+ self.condition= states[self.state]\n+ self.cmdline = string.replace(self.cmdline,'\\x00',' ')\n+ self.cmdline = string.strip(self.cmdline)\n+ \n+ #ps_default = ['user','pid','cpu_percent','total_memory','resident_memory',\n+ # 'state','start_time','cmdline']\n+ ps_default = ['user','pid','cpu_percent','total_memory','resident_memory',\n+ 'state','total2_time','cmdline']\n+ def labels(self):\n+ s = \"%-8s %5s %4s %4s %8s %8s %1s %10s %3s\" % \\\n+ ('USER','PID','%CPU', '%MEM', 'TOTAL MB', ' RES MB',\n+ 'ST', 'RT-D:H:M:S', 'CMD')\n+ return s \n+ def labels_with_name(self):\n+ s = \"%-6s %s\" % ('MACHINE',self.labels())\n+ return s\n+ def str_with_name(self):\n+ s = \"%-6s %-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n+ (self.machine[-6:], self.user,self.pid,self.cpu_percent,\n+ self.memory_percent, self.total_memory, self.resident_memory,\n+ self.state, self.total_time2) \n+ bytes_left = 80 - len(s) - 1\n+ if len(self.cmdline) > bytes_left:\n+ s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n+ else: \n+ s = s + self.cmdline\n+ return s\n+ def __str__(self):\n+ s = \"%-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n+ (self.user,self.pid,self.cpu_percent,self.memory_percent,\n+ self.total_memory, self.resident_memory, self.state, \n+ self.total_time2) \n+ bytes_left = 80 - len(s) - 1\n+ if len(self.cmdline) > bytes_left:\n+ s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n+ else: \n+ s = s + self.cmdline\n+ return \n+ \n+ \n+ def ps_list(sort_by='cpu',**filters):\n+ import os, glob\n+ current = os.path.abspath('.')\n+ os.chdir('/proc') \n+ procs = glob.glob('[0-9]*')\n+ results = []\n+ seconds_since_boot = uptime_info()['uptime']\n+ total_memory = mem_info()['mem_total'] \n+ for proc in procs:\n+ results.append(process(proc,seconds_since_boot,total_memory))\n+ os.chdir(current)\n+ return ps_sort(results,sort_by,**filters)\n+ # end linux specific\n+else:\n+ # punt. At least there exist a class so that unpickling won't fail.\n+ def uptime_info():\n+ raise NotImplemented, 'not implemented on this architecture'\n+ def cpu_info():\n+ raise NotImplemented, 'not implemented on this architecture'\n+ def filter_name(name):\n+ raise NotImplemented, 'not implemented on this architecture' \n+ def mem_info():\n+ raise NotImplemented, 'not implemented on this architecture'\n+ def load_avg():\n+ raise NotImplemented, 'not implemented on this architecture'\n+ def machine_info():\n+ raise NotImplemented, 'not implemented on this architecture'\n+ \n+ uid_cache = {}\n+ gid_cache = {}\n+ def user_from_uid(uid):\n+ raise NotImplemented, 'not implemented on this architecture'\n+ def group_from_gid(gid):\n+ raise NotImplemented, 'not implemented on this architecture'\n+ def ps_list(sort_by='cpu',**filters):\n+ raise NotImplemented, 'not implemented on this architecture' \n+ class process:\n+ def labels(self):\n+ s = \"%-8s %5s %4s %4s %8s %8s %1s %10s %3s\" % \\\n+ ('USER','PID','%CPU', '%MEM', 'TOTAL MB', ' RES MB',\n+ 'ST', 'RT-D:H:M:S', 'CMD')\n+ return s \n+ def labels_with_name(self):\n+ s = \"%-6s %s\" % ('MACHINE',self.labels())\n+ return s\n+ def str_with_name(self):\n+ s = \"%-6s %-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n+ (self.machine[-6:], self.user,self.pid,self.cpu_percent,\n+ self.memory_percent, self.total_memory, self.resident_memory,\n+ self.state, self.total_time2) \n+ bytes_left = 80 - len(s) - 1\n+ if len(self.cmdline) > bytes_left:\n+ s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n+ else: \n+ s = s + self.cmdline\n+ return s\n+ \n+ def __str__(self):\n+ s = \"%-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n+ (self.user,self.pid,self.cpu_percent,self.memory_percent,\n+ self.total_memory, self.resident_memory, self.state, \n+ self.total_time2) \n+ bytes_left = 80 - len(s) - 1\n+ if len(self.cmdline) > bytes_left:\n+ s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n+ else: \n+ s = s + self.cmdline\n+ return \n+\n+# these are all general to any OS\n+\n+def cmp_pid(x,y):\n+ return cmp(x.pid,y.pid)\n+def cmp_cpu(x,y):\n+ return -cmp(x.cpu_percent,y.cpu_percent)\n+def cmp_user(x,y):\n+ return cmp(x.user,y.user)\n+def cmp_machine(x,y):\n+ return cmp(x.machine,y.machine)\n+def cmp_memory(x,y):\n+ return -cmp(x.memory_percent,y.memory_percent)\n+def cmp_state(x,y):\n+ return cmp(x.state,y.state)\n+def cmp_command(x,y):\n+ return cmp(x.cmdline,y.cmdline)\n+ \n+ps_cmp={}\n+ps_cmp['pid'] = cmp_pid \n+ps_cmp['cpu'] = cmp_cpu \n+ps_cmp['user'] = cmp_user\n+ps_cmp['machine'] = cmp_machine\n+ps_cmp['memory'] = cmp_memory\n+ps_cmp['state'] = cmp_state\n+ps_cmp['command'] = cmp_command\n+\n+from fnmatch import fnmatch\n+\n+def filter_machine(x,filt):\n+ return (fnmatch(x.machine,filt) or fnmatch(x.long_machine,filt))\n+def filter_user(x,filt):\n+ return (fnmatch(x.user,filt)) \n+def filter_state(x,filt):\n+ return (fnmatch(x.state,filt))\n+def filter_command(x,filt):\n+ return (fnmatch(x.cmdline,filt))\n+def filter_cpu(x,filt):\n+ return eval(str(x.cpu_percent) + filt)\n+def filter_memory(x,filt):\n+ return eval(str(x.memory_percent) + filt)\n+def filter_mb(x,filt):\n+ return eval(str(x.total_memory) + filt)\n+ \n+ps_filter={}\n+ps_filter['user'] = filter_user\n+ps_filter['machine'] = filter_machine\n+ps_filter['state'] = filter_state\n+ps_filter['command'] = filter_command\n+ps_filter['memory'] = filter_memory\n+ps_filter['mb'] = filter_mb\n+ps_filter['cpu'] = filter_cpu\n+\n+def ps(sort_by='cpu',**filters):\n+ psl = ps_list(sort_by,**filters)\n+ if len(psl):\n+ print psl[0].labels_with_name()\n+ for i in psl: \n+ print i\n+ \n+def ps_sort(psl,sort_by='cpu',**filters):\n+ for f in filters.keys():\n+ try:\n+ filt = ps_filter[f]\n+ filt_str = filters[f]\n+ psl = filter(lambda x,filt=filt,y=filt_str:filt(x,y),psl)\n+ except KeyError:\n+ print 'warning: \"', f, '\"is an invalid key for filtering command.'\n+ print ' ', 'use one of the following:', str(ps_filter.keys())\n+ try:\n+ compare = ps_cmp[sort_by] \n+ psl.sort(compare)\n+ except KeyError:\n+ print 'warning: \"', sort_by, '\"is an invalid choice for sorting.'\n+ print ' ', 'use one of the following:', str(ps_cmp.keys())\n+ return psl\n+\n+\n", "added_lines": 494, "deleted_lines": 0, "source_code": "#! /usr/bin/python\n# Currently only implemented for linux...need to do win32\n# I thought of making OS specific modules that were chosen \n# based on OS much like path works, but I think this will\n# break pickling when process objects are passed between\n# two OSes because the module name is saved in the pickle.\n# A Unix process info object passed to a Windows machine\n# would attempt to import the linux proc module and fail.\n# Using a single module with if-then-else I think prevents\n# this name problem (but it isn't as pretty...)\n\nimport sys,string\n\nif string.find(sys.platform,'linux') != -1:\n # begin linux specific\n import string,os,stat\n import pwd, grp\n \n hertz = 100. #standard value for jiffies (in seconds) on Linux.\n states = {'R':'RUNNING','S':'SLEEPING','Z':'ZOMBIE',\n 'T':'TRACED','D':'DEEPSLEEP'}\n \n import socket\n long_machine_name = socket.gethostname()\n machine_name = string.split(long_machine_name,'.')[0]\n \n def uptime_info():\n f = open(\"/proc/uptime\")\n line = f.readline()\n field = string.split(line) \n info={}\n info['uptime'] = eval(field[0])\n info['idle'] = eval(field[1])\n return info\n \n def cpu_info():\n \"\"\"* We'll assume SMP machines have identical processors\n \n *\"\"\"\n f = open(\"/proc/cpuinfo\")\n lines = f.readlines()\n pairs = map(lambda x,y=':':string.split(x,y),lines)\n info={}\n for line in pairs:\n if len(line) > 1: \n key = string.strip(line[0])\n value = string.strip(line[1])\n try: \n info[key] = eval(value)\n except: \n info[key] = value\n sub_info = {}\n sub_info['cpu_count'] = info['processor'] + 1\n sub_info['cpu_type'] = filter_name(info['model name'])\n sub_info['cpu_cache'] = eval(string.split(info['cache size'])[0])\n sub_info['cpu_speed'] = round(info['cpu MHz']/1000.,1) # in GHz\n sub_info['cpu_bogomips'] = info['bogomips'] \n #print sub_info \n return sub_info\n \n def filter_name(name):\n \"\"\"* Try to shorten the verbose names in cpuinfo *\"\"\"\n if string.find(name,'Pentium III') != -1:\n return 'P3'\n elif string.find(name,'Athlon') != -1:\n return 'Athlon'\n elif string.find(name,'Pentium II') != -1:\n return 'P2'\n return name\n \n \n def mem_info():\n f = open(\"/proc/meminfo\")\n l = f.readlines()\n x = string.split(l[1])\n total = eval(x[1])\n used = eval(x[2])\n free = eval(x[3])\n shared = eval(x[4])\n buffers = eval(x[5])\n cached = eval(x[6])\n \n x = string.split(l[2])\n stotal = eval(x[1])\n sused = eval(x[2])\n sfree = eval(x[3])\n \n memtotal = os.stat(\"/proc/kcore\")[stat.ST_SIZE]\n \n m = 1024*1024\n #print \"Memory RAM : %d MB (%d MB kernel, %d MB free)\" % (memtotal/m, (memtotal-total)/m, free/m)\n #print \" usage : %d MB shared %d MB buffers %d MB cached\" % (shared/m, buffers/m, cached/m)\n #print \"Swap area : %d MB (%d MB used)\" % (stotal/m, sused/m)\n info = {}\n info['mem_total'] = memtotal/m\n info['mem_kernel'] = (memtotal-total)/m\n info['mem_free'] = free/m\n info['swap_total'] = stotal/m\n info['swap_free'] = (stotal-sused)/m\n return info\n \n def load_avg():\n f = open(\"/proc/loadavg\")\n line = f.readline()\n field = string.split(line) \n info={}\n info['load_1'] = eval(field[0])\n info['load_5'] = eval(field[1])\n info['load_15'] = eval(field[2])\n return info\n \n def machine_info():\n all = load_avg()\n all.update(cpu_info())\n all.update(mem_info())\n all['long_name'] = long_machine_name\n all['name'] = machine_name\n return all\n \n \n uid_cache = {}\n gid_cache = {}\n def user_from_uid(uid):\n global uid_cache\n try:\n user = uid_cache[uid]\n except:\n user = pwd.getpwuid(uid)[0]\n uid_cache[uid] = user\n return user \n \n def group_from_gid(gid):\n global gid_cache\n try:\n group = gid_cache[gid]\n except:\n group = grp.getgrgid(gid)[0]\n gid_cache[gid] =group \n return group \n \n # Yes, this is slow. It also works and is pure Python (easy).\n # If your looking to do a real top, or fast ps command use SIWG to wrap the\n # ps and top code. This would give much better performance, be more robust,\n # and make the generally world a happier place. Please send it in when \n # your finished!\n # This is all pretty much stolen from readproc.c in the procps \n # package (scour the web).\n \n class process:\n def __init__(self,pid,seconds_since_boot=None,total_memory=None):\n self.info(int(pid),seconds_since_boot,total_memory)\n def info(self,pid,seconds_since_boot=None,total_memory=None):\n self.status2proc(pid)\n self.stat2proc(pid)\n self.statm2proc(pid)\n self.get_cmdline(pid)\n #self.get_environ(pid)\n if self.state == 'Z':\n self.cmd = self.cmd + \"\"\n self.beautify(seconds_since_boot,total_memory)\n self.pid = pid\n self.machine = machine_name\n self.long_machine = long_machine_name\n def status2proc(self,pid):\n f = open(\"/proc/%d/status\" % pid)\n lines = f.readlines()\n #line = map(string.split,lines)\n id = map(string.split,lines[4:6])\n \n #self.cmd = line[0][1]\n #self.state = line[1][2]\n self.ruid,self.euid,self.suid,self.fuid = map(int,id[0][1:])\n self.rgid,self.egid,self.sgid,self.fgid = map(int,id[1][1:])\n #self.euid = int(id[0][1])\n #self.egid = int(id[1][1])\n #self.vm_size = long(line[7][1])\n #self.vm_lock = long(line[8][1])\n #self.vm_rss = long(line[9][1])\n #self.vm_data = long(line[10][1])\n #self.vm_stack = long(line[11][1])\n #self.vm_exe = long(line[12][1])\n #self.vm_lib = long(line[13][1])\n \n #translate id's to user and group names\n #self.ruser = user_from_uid(self.ruid)\n #self.suser = user_from_uid(self.suid)\n self.euser = user_from_uid(self.euid)\n #self.fuser = user_from_uid(self.fuid)\n #self.rgroup = group_from_gid(self.rgid)\n #self.sgroup = group_from_gid(self.sgid)\n self.egroup = group_from_gid(self.egid)\n #self.fgroup = group_from_gid(self.fgid)\n \n def stat2proc(self,pid):\n # oh, to have sscanf... (I'm sure it is somewhere)\n f = open(\"/proc/%d/stat\" % pid)\n s = f.read(-1)\n f.close()\n cmd = string.rfind(s,'(') + 1\n begin = string.rfind(s,')')\n self.cmd = s[cmd:begin]\n begin = begin + 2\n field = string.split(s[begin:])\n self.state = field[0]\n self.ppid = int(field[1])\n #self.pgrp = int(field[2])\n #self.session = int(field[3])\n self.tty = int(field[4])\n #self.tpgid = eval(field[5])\n #self.flags = eval(field[6])\n #self.min_flt = long(field[7])\n #self.cmin_flt = long(field[8])\n #self.maj_flt = long(field[9])\n #self.cmaj_flt = long(field[10])\n self.utime = long(field[11])\n self.stime = long(field[12])\n self.cutime = int(field[13])\n self.cstime = int(field[14])\n self.priority = int(field[15])\n self.nice = int(field[16])\n #self.timeout = eval(field[17])\n #self.it_real_value = eval(field[18])\n self.start_time = long(field[19])\n self.vsize = long(field[20])\n self.rss = long(field[21])\n self.rss_rlim = long(field[22])\n #self.start_code = long(field[23])\n #self.end_code = long(field[24])\n self.start_stack = long(field[25])\n #self.kstk_esp = long(field[26])\n #self.kstk_eip = long(field[27])\n #self.wchan = long(field[29])\n #self.nswap = long(field[30])\n self.cnswap = long(field[31])\n if self.tty == 0: self.tty=-1\n def statm2proc(self,pid):\n f = open(\"/proc/%d/statm\" % pid)\n s = f.read(-1)\n f.close()\n field = string.split(s)\n self.size = int(field[0])\n self.resident = int(field[1])\n #self.share = int(field[2])\n #self.trs = int(field[3])\n #self.lrs = int(field[4])\n #self.drs = int(field[5])\n #self.dt = int(field[6])\n def get_cmdline(self,pid):\n f = open(\"/proc/%d/cmdline\" % pid)\n self.cmdline = f.read(-1)\n f.close() \n def get_environ(self,pid):\n f = open(\"/proc/%d/environ\" % pid)\n self.cmdline = f.read(-1)\n f.close()\n \n def beautify(self,seconds_since_boot=None,total_memory=None):\n \"\"\"* total_memory in MB \n *\"\"\"\n if seconds_since_boot is None:\n seconds_since_boot = uptime_info()['uptime']\n if total_memory is None:\n total_memory = mem_info()['mem_total']\n self.beautify_user()\n self.beautify_cpu(seconds_since_boot)\n self.beautify_memory(total_memory)\n self.beautify_state()\n def beautify_user(self): \n self.uid = self.euid\n self.user = self.euser\n self.gid = self.egid\n self.group = self.egroup\n \n def beautify_cpu(self,seconds_since_boot):\n include_dead_children = 0 \n self.total_time = (self.utime + self.stime) / hertz \n self.wall_time = seconds_since_boot - self.start_time /hertz\n if include_dead_children:\n self.total_time = self.total_time + \\\n (self.cutime + self.cstime) / hertz\n self.pcpu = 0\n if self.wall_time:\n self.pcpu = self.total_time * 1000. / self.wall_time\n if self.pcpu > 999: \n self.pcpu = 999.\n \n self.cpu_percent = self.pcpu / 10.\n #foramt time into a days:hours:minutes:seconds string\n t = long(self.wall_time)\n t,ss = divmod(t,60)\n t,mm = divmod(t,60)\n t,hh = divmod(t,24)\n dd = t\n self.wall_time2 = \"%2d:%2d:%2d:%2d\" % (dd,hh,mm,ss)\n t = long(self.total_time) \n t,ss = divmod(t,60)\n t,mm = divmod(t,60)\n t,hh = divmod(t,24)\n dd = t\n self.total_time2 = \"%2d:%2d:%2d:%2d\" % (dd,hh,mm,ss)\n \n def beautify_memory(self,total_memory):\n \"\"\"* translate memory values to MB, and percentage\n *\"\"\"\n self.total_memory = self.size * 4 / 1024.\n self.resident_memory = self.resident * 4/ 1024.\n self.memory_percent = self.resident_memory / total_memory * 100\n def beautify_state(self):\n self.condition= states[self.state]\n self.cmdline = string.replace(self.cmdline,'\\x00',' ')\n self.cmdline = string.strip(self.cmdline)\n \n #ps_default = ['user','pid','cpu_percent','total_memory','resident_memory',\n # 'state','start_time','cmdline']\n ps_default = ['user','pid','cpu_percent','total_memory','resident_memory',\n 'state','total2_time','cmdline']\n def labels(self):\n s = \"%-8s %5s %4s %4s %8s %8s %1s %10s %3s\" % \\\n ('USER','PID','%CPU', '%MEM', 'TOTAL MB', ' RES MB',\n 'ST', 'RT-D:H:M:S', 'CMD')\n return s \n def labels_with_name(self):\n s = \"%-6s %s\" % ('MACHINE',self.labels())\n return s\n def str_with_name(self):\n s = \"%-6s %-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n (self.machine[-6:], self.user,self.pid,self.cpu_percent,\n self.memory_percent, self.total_memory, self.resident_memory,\n self.state, self.total_time2) \n bytes_left = 80 - len(s) - 1\n if len(self.cmdline) > bytes_left:\n s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n else: \n s = s + self.cmdline\n return s\n def __str__(self):\n s = \"%-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n (self.user,self.pid,self.cpu_percent,self.memory_percent,\n self.total_memory, self.resident_memory, self.state, \n self.total_time2) \n bytes_left = 80 - len(s) - 1\n if len(self.cmdline) > bytes_left:\n s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n else: \n s = s + self.cmdline\n return \n \n \n def ps_list(sort_by='cpu',**filters):\n import os, glob\n current = os.path.abspath('.')\n os.chdir('/proc') \n procs = glob.glob('[0-9]*')\n results = []\n seconds_since_boot = uptime_info()['uptime']\n total_memory = mem_info()['mem_total'] \n for proc in procs:\n results.append(process(proc,seconds_since_boot,total_memory))\n os.chdir(current)\n return ps_sort(results,sort_by,**filters)\n # end linux specific\nelse:\n # punt. At least there exist a class so that unpickling won't fail.\n def uptime_info():\n raise NotImplemented, 'not implemented on this architecture'\n def cpu_info():\n raise NotImplemented, 'not implemented on this architecture'\n def filter_name(name):\n raise NotImplemented, 'not implemented on this architecture' \n def mem_info():\n raise NotImplemented, 'not implemented on this architecture'\n def load_avg():\n raise NotImplemented, 'not implemented on this architecture'\n def machine_info():\n raise NotImplemented, 'not implemented on this architecture'\n \n uid_cache = {}\n gid_cache = {}\n def user_from_uid(uid):\n raise NotImplemented, 'not implemented on this architecture'\n def group_from_gid(gid):\n raise NotImplemented, 'not implemented on this architecture'\n def ps_list(sort_by='cpu',**filters):\n raise NotImplemented, 'not implemented on this architecture' \n class process:\n def labels(self):\n s = \"%-8s %5s %4s %4s %8s %8s %1s %10s %3s\" % \\\n ('USER','PID','%CPU', '%MEM', 'TOTAL MB', ' RES MB',\n 'ST', 'RT-D:H:M:S', 'CMD')\n return s \n def labels_with_name(self):\n s = \"%-6s %s\" % ('MACHINE',self.labels())\n return s\n def str_with_name(self):\n s = \"%-6s %-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n (self.machine[-6:], self.user,self.pid,self.cpu_percent,\n self.memory_percent, self.total_memory, self.resident_memory,\n self.state, self.total_time2) \n bytes_left = 80 - len(s) - 1\n if len(self.cmdline) > bytes_left:\n s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n else: \n s = s + self.cmdline\n return s\n \n def __str__(self):\n s = \"%-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\\n (self.user,self.pid,self.cpu_percent,self.memory_percent,\n self.total_memory, self.resident_memory, self.state, \n self.total_time2) \n bytes_left = 80 - len(s) - 1\n if len(self.cmdline) > bytes_left:\n s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]\n else: \n s = s + self.cmdline\n return \n\n# these are all general to any OS\n\ndef cmp_pid(x,y):\n return cmp(x.pid,y.pid)\ndef cmp_cpu(x,y):\n return -cmp(x.cpu_percent,y.cpu_percent)\ndef cmp_user(x,y):\n return cmp(x.user,y.user)\ndef cmp_machine(x,y):\n return cmp(x.machine,y.machine)\ndef cmp_memory(x,y):\n return -cmp(x.memory_percent,y.memory_percent)\ndef cmp_state(x,y):\n return cmp(x.state,y.state)\ndef cmp_command(x,y):\n return cmp(x.cmdline,y.cmdline)\n \nps_cmp={}\nps_cmp['pid'] = cmp_pid \nps_cmp['cpu'] = cmp_cpu \nps_cmp['user'] = cmp_user\nps_cmp['machine'] = cmp_machine\nps_cmp['memory'] = cmp_memory\nps_cmp['state'] = cmp_state\nps_cmp['command'] = cmp_command\n\nfrom fnmatch import fnmatch\n\ndef filter_machine(x,filt):\n return (fnmatch(x.machine,filt) or fnmatch(x.long_machine,filt))\ndef filter_user(x,filt):\n return (fnmatch(x.user,filt)) \ndef filter_state(x,filt):\n return (fnmatch(x.state,filt))\ndef filter_command(x,filt):\n return (fnmatch(x.cmdline,filt))\ndef filter_cpu(x,filt):\n return eval(str(x.cpu_percent) + filt)\ndef filter_memory(x,filt):\n return eval(str(x.memory_percent) + filt)\ndef filter_mb(x,filt):\n return eval(str(x.total_memory) + filt)\n \nps_filter={}\nps_filter['user'] = filter_user\nps_filter['machine'] = filter_machine\nps_filter['state'] = filter_state\nps_filter['command'] = filter_command\nps_filter['memory'] = filter_memory\nps_filter['mb'] = filter_mb\nps_filter['cpu'] = filter_cpu\n\ndef ps(sort_by='cpu',**filters):\n psl = ps_list(sort_by,**filters)\n if len(psl):\n print psl[0].labels_with_name()\n for i in psl: \n print i\n \ndef ps_sort(psl,sort_by='cpu',**filters):\n for f in filters.keys():\n try:\n filt = ps_filter[f]\n filt_str = filters[f]\n psl = filter(lambda x,filt=filt,y=filt_str:filt(x,y),psl)\n except KeyError:\n print 'warning: \"', f, '\"is an invalid key for filtering command.'\n print ' ', 'use one of the following:', str(ps_filter.keys())\n try:\n compare = ps_cmp[sort_by] \n psl.sort(compare)\n except KeyError:\n print 'warning: \"', sort_by, '\"is an invalid choice for sorting.'\n print ' ', 'use one of the following:', str(ps_cmp.keys())\n return psl\n\n\n", "source_code_before": null, "methods": [ { "name": "uptime_info", "long_name": "uptime_info( )", "filename": "proc.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "cpu_info", "long_name": "cpu_info( )", "filename": "proc.py", "nloc": 20, "complexity": 4, "token_count": 173, "parameters": [], "start_line": 36, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "filter_name", "long_name": "filter_name( name )", "filename": "proc.py", "nloc": 8, "complexity": 4, "token_count": 53, "parameters": [ "name" ], "start_line": 61, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "mem_info", "long_name": "mem_info( )", "filename": "proc.py", "nloc": 23, "complexity": 1, "token_count": 192, "parameters": [], "start_line": 72, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "load_avg", "long_name": "load_avg( )", "filename": "proc.py", "nloc": 9, "complexity": 1, "token_count": 67, "parameters": [], "start_line": 102, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "machine_info", "long_name": "machine_info( )", "filename": "proc.py", "nloc": 7, "complexity": 1, "token_count": 39, "parameters": [], "start_line": 112, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "user_from_uid", "long_name": "user_from_uid( uid )", "filename": "proc.py", "nloc": 8, "complexity": 2, "token_count": 36, "parameters": [ "uid" ], "start_line": 123, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "group_from_gid", "long_name": "group_from_gid( gid )", "filename": "proc.py", "nloc": 8, "complexity": 2, "token_count": 36, "parameters": [ "gid" ], "start_line": 132, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , pid , seconds_since_boot = None , total_memory = None )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 28, "parameters": [ "self", "pid", "seconds_since_boot", "total_memory" ], "start_line": 150, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "info", "long_name": "info( self , pid , seconds_since_boot = None , total_memory = None )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 78, "parameters": [ "self", "pid", "seconds_since_boot", "total_memory" ], "start_line": 152, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 2 }, { "name": "status2proc", "long_name": "status2proc( self , pid )", "filename": "proc.py", "nloc": 8, "complexity": 1, "token_count": 115, "parameters": [ "self", "pid" ], "start_line": 164, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 2 }, { "name": "stat2proc", "long_name": "stat2proc( self , pid )", "filename": "proc.py", "nloc": 25, "complexity": 2, "token_count": 253, "parameters": [ "self", "pid" ], "start_line": 194, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 2 }, { "name": "statm2proc", "long_name": "statm2proc( self , pid )", "filename": "proc.py", "nloc": 7, "complexity": 1, "token_count": 59, "parameters": [ "self", "pid" ], "start_line": 236, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 }, { "name": "get_cmdline", "long_name": "get_cmdline( self , pid )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "pid" ], "start_line": 248, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_environ", "long_name": "get_environ( self , pid )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "pid" ], "start_line": 252, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "beautify", "long_name": "beautify( self , seconds_since_boot = None , total_memory = None )", "filename": "proc.py", "nloc": 9, "complexity": 3, "token_count": 62, "parameters": [ "self", "seconds_since_boot", "total_memory" ], "start_line": 257, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "beautify_user", "long_name": "beautify_user( self )", "filename": "proc.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self" ], "start_line": 268, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "beautify_cpu", "long_name": "beautify_cpu( self , seconds_since_boot )", "filename": "proc.py", "nloc": 25, "complexity": 4, "token_count": 218, "parameters": [ "self", "seconds_since_boot" ], "start_line": 274, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 2 }, { "name": "beautify_memory", "long_name": "beautify_memory( self , total_memory )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self", "total_memory" ], "start_line": 302, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 2 }, { "name": "beautify_state", "long_name": "beautify_state( self )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 308, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "labels", "long_name": "labels( self )", "filename": "proc.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 317, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "labels_with_name", "long_name": "labels_with_name( self )", "filename": "proc.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 322, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 2 }, { "name": "str_with_name", "long_name": "str_with_name( self )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 109, "parameters": [ "self" ], "start_line": 325, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 99, "parameters": [ "self" ], "start_line": 336, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "ps_list", "long_name": "ps_list( sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 12, "complexity": 2, "token_count": 92, "parameters": [ "sort_by", "filters" ], "start_line": 349, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "uptime_info", "long_name": "uptime_info( )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 364, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "cpu_info", "long_name": "cpu_info( )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 366, "end_line": 367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "filter_name", "long_name": "filter_name( name )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "name" ], "start_line": 368, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "mem_info", "long_name": "mem_info( )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 370, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "load_avg", "long_name": "load_avg( )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 372, "end_line": 373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "machine_info", "long_name": "machine_info( )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 374, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "user_from_uid", "long_name": "user_from_uid( uid )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "uid" ], "start_line": 379, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "group_from_gid", "long_name": "group_from_gid( gid )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "gid" ], "start_line": 381, "end_line": 382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "ps_list", "long_name": "ps_list( sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "sort_by", "filters" ], "start_line": 383, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "labels", "long_name": "labels( self )", "filename": "proc.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 386, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "labels_with_name", "long_name": "labels_with_name( self )", "filename": "proc.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 391, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 2 }, { "name": "str_with_name", "long_name": "str_with_name( self )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 109, "parameters": [ "self" ], "start_line": 394, "end_line": 404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 99, "parameters": [ "self" ], "start_line": 406, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "cmp_pid", "long_name": "cmp_pid( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 420, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_cpu", "long_name": "cmp_cpu( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "y" ], "start_line": 422, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_user", "long_name": "cmp_user( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 424, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_machine", "long_name": "cmp_machine( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 426, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_memory", "long_name": "cmp_memory( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "y" ], "start_line": 428, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_state", "long_name": "cmp_state( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 430, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_command", "long_name": "cmp_command( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 432, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_machine", "long_name": "filter_machine( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 2, "token_count": 27, "parameters": [ "x", "filt" ], "start_line": 446, "end_line": 447, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_user", "long_name": "filter_user( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "filt" ], "start_line": 448, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_state", "long_name": "filter_state( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "filt" ], "start_line": 450, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_command", "long_name": "filter_command( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "filt" ], "start_line": 452, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_cpu", "long_name": "filter_cpu( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "filt" ], "start_line": 454, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_memory", "long_name": "filter_memory( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "filt" ], "start_line": 456, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_mb", "long_name": "filter_mb( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "filt" ], "start_line": 458, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "ps", "long_name": "ps( sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 6, "complexity": 3, "token_count": 41, "parameters": [ "sort_by", "filters" ], "start_line": 470, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "ps_sort", "long_name": "ps_sort( psl , sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 16, "complexity": 4, "token_count": 119, "parameters": [ "psl", "sort_by", "filters" ], "start_line": 477, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "beautify_cpu", "long_name": "beautify_cpu( self , seconds_since_boot )", "filename": "proc.py", "nloc": 25, "complexity": 4, "token_count": 218, "parameters": [ "self", "seconds_since_boot" ], "start_line": 274, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 2 }, { "name": "load_avg", "long_name": "load_avg( )", "filename": "proc.py", "nloc": 9, "complexity": 1, "token_count": 67, "parameters": [], "start_line": 102, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "group_from_gid", "long_name": "group_from_gid( gid )", "filename": "proc.py", "nloc": 8, "complexity": 2, "token_count": 36, "parameters": [ "gid" ], "start_line": 132, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_environ", "long_name": "get_environ( self , pid )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "pid" ], "start_line": 252, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "labels_with_name", "long_name": "labels_with_name( self )", "filename": "proc.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 322, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 2 }, { "name": "get_cmdline", "long_name": "get_cmdline( self , pid )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "pid" ], "start_line": 248, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "beautify_user", "long_name": "beautify_user( self )", "filename": "proc.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self" ], "start_line": 268, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "filter_mb", "long_name": "filter_mb( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "filt" ], "start_line": 458, "end_line": 459, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_machine", "long_name": "cmp_machine( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 426, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 99, "parameters": [ "self" ], "start_line": 336, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "beautify_memory", "long_name": "beautify_memory( self , total_memory )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self", "total_memory" ], "start_line": 302, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 2 }, { "name": "filter_user", "long_name": "filter_user( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "filt" ], "start_line": 448, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "statm2proc", "long_name": "statm2proc( self , pid )", "filename": "proc.py", "nloc": 7, "complexity": 1, "token_count": 59, "parameters": [ "self", "pid" ], "start_line": 236, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 }, { "name": "beautify", "long_name": "beautify( self , seconds_since_boot = None , total_memory = None )", "filename": "proc.py", "nloc": 9, "complexity": 3, "token_count": 62, "parameters": [ "self", "seconds_since_boot", "total_memory" ], "start_line": 257, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "__init__", "long_name": "__init__( self , pid , seconds_since_boot = None , total_memory = None )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 28, "parameters": [ "self", "pid", "seconds_since_boot", "total_memory" ], "start_line": 150, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "ps_list", "long_name": "ps_list( sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 12, "complexity": 2, "token_count": 92, "parameters": [ "sort_by", "filters" ], "start_line": 349, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "cmp_pid", "long_name": "cmp_pid( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 420, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cpu_info", "long_name": "cpu_info( )", "filename": "proc.py", "nloc": 20, "complexity": 4, "token_count": 173, "parameters": [], "start_line": 36, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "ps_sort", "long_name": "ps_sort( psl , sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 16, "complexity": 4, "token_count": 119, "parameters": [ "psl", "sort_by", "filters" ], "start_line": 477, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "filter_machine", "long_name": "filter_machine( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 2, "token_count": 27, "parameters": [ "x", "filt" ], "start_line": 446, "end_line": 447, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_command", "long_name": "filter_command( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "filt" ], "start_line": 452, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "stat2proc", "long_name": "stat2proc( self , pid )", "filename": "proc.py", "nloc": 25, "complexity": 2, "token_count": 253, "parameters": [ "self", "pid" ], "start_line": 194, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 2 }, { "name": "filter_name", "long_name": "filter_name( name )", "filename": "proc.py", "nloc": 8, "complexity": 4, "token_count": 53, "parameters": [ "name" ], "start_line": 61, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "user_from_uid", "long_name": "user_from_uid( uid )", "filename": "proc.py", "nloc": 8, "complexity": 2, "token_count": 36, "parameters": [ "uid" ], "start_line": 123, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "filter_cpu", "long_name": "filter_cpu( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "filt" ], "start_line": 454, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "status2proc", "long_name": "status2proc( self , pid )", "filename": "proc.py", "nloc": 8, "complexity": 1, "token_count": 115, "parameters": [ "self", "pid" ], "start_line": 164, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 2 }, { "name": "machine_info", "long_name": "machine_info( )", "filename": "proc.py", "nloc": 7, "complexity": 1, "token_count": 39, "parameters": [], "start_line": 112, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "labels", "long_name": "labels( self )", "filename": "proc.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 317, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 2 }, { "name": "cmp_state", "long_name": "cmp_state( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 430, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "cmp_cpu", "long_name": "cmp_cpu( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "y" ], "start_line": 422, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "filter_memory", "long_name": "filter_memory( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "filt" ], "start_line": 456, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "info", "long_name": "info( self , pid , seconds_since_boot = None , total_memory = None )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 78, "parameters": [ "self", "pid", "seconds_since_boot", "total_memory" ], "start_line": 152, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 2 }, { "name": "cmp_user", "long_name": "cmp_user( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 424, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "uptime_info", "long_name": "uptime_info( )", "filename": "proc.py", "nloc": 8, "complexity": 1, "token_count": 55, "parameters": [], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "cmp_command", "long_name": "cmp_command( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "y" ], "start_line": 432, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "mem_info", "long_name": "mem_info( )", "filename": "proc.py", "nloc": 23, "complexity": 1, "token_count": 192, "parameters": [], "start_line": 72, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "cmp_memory", "long_name": "cmp_memory( x , y )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "x", "y" ], "start_line": 428, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "str_with_name", "long_name": "str_with_name( self )", "filename": "proc.py", "nloc": 11, "complexity": 2, "token_count": 109, "parameters": [ "self" ], "start_line": 325, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 2 }, { "name": "filter_state", "long_name": "filter_state( x , filt )", "filename": "proc.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "x", "filt" ], "start_line": 450, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "beautify_state", "long_name": "beautify_state( self )", "filename": "proc.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 308, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "ps", "long_name": "ps( sort_by = 'cpu' , ** filters )", "filename": "proc.py", "nloc": 6, "complexity": 3, "token_count": 41, "parameters": [ "sort_by", "filters" ], "start_line": 470, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "nloc": 375, "complexity": 80, "token_count": 3033, "diff_parsed": { "added": [ "#! /usr/bin/python", "# Currently only implemented for linux...need to do win32", "# I thought of making OS specific modules that were chosen", "# based on OS much like path works, but I think this will", "# break pickling when process objects are passed between", "# two OSes because the module name is saved in the pickle.", "# A Unix process info object passed to a Windows machine", "# would attempt to import the linux proc module and fail.", "# Using a single module with if-then-else I think prevents", "# this name problem (but it isn't as pretty...)", "", "import sys,string", "", "if string.find(sys.platform,'linux') != -1:", " # begin linux specific", " import string,os,stat", " import pwd, grp", "", " hertz = 100. #standard value for jiffies (in seconds) on Linux.", " states = {'R':'RUNNING','S':'SLEEPING','Z':'ZOMBIE',", " 'T':'TRACED','D':'DEEPSLEEP'}", "", " import socket", " long_machine_name = socket.gethostname()", " machine_name = string.split(long_machine_name,'.')[0]", "", " def uptime_info():", " f = open(\"/proc/uptime\")", " line = f.readline()", " field = string.split(line)", " info={}", " info['uptime'] = eval(field[0])", " info['idle'] = eval(field[1])", " return info", "", " def cpu_info():", " \"\"\"* We'll assume SMP machines have identical processors", "", " *\"\"\"", " f = open(\"/proc/cpuinfo\")", " lines = f.readlines()", " pairs = map(lambda x,y=':':string.split(x,y),lines)", " info={}", " for line in pairs:", " if len(line) > 1:", " key = string.strip(line[0])", " value = string.strip(line[1])", " try:", " info[key] = eval(value)", " except:", " info[key] = value", " sub_info = {}", " sub_info['cpu_count'] = info['processor'] + 1", " sub_info['cpu_type'] = filter_name(info['model name'])", " sub_info['cpu_cache'] = eval(string.split(info['cache size'])[0])", " sub_info['cpu_speed'] = round(info['cpu MHz']/1000.,1) # in GHz", " sub_info['cpu_bogomips'] = info['bogomips']", " #print sub_info", " return sub_info", "", " def filter_name(name):", " \"\"\"* Try to shorten the verbose names in cpuinfo *\"\"\"", " if string.find(name,'Pentium III') != -1:", " return 'P3'", " elif string.find(name,'Athlon') != -1:", " return 'Athlon'", " elif string.find(name,'Pentium II') != -1:", " return 'P2'", " return name", "", "", " def mem_info():", " f = open(\"/proc/meminfo\")", " l = f.readlines()", " x = string.split(l[1])", " total = eval(x[1])", " used = eval(x[2])", " free = eval(x[3])", " shared = eval(x[4])", " buffers = eval(x[5])", " cached = eval(x[6])", "", " x = string.split(l[2])", " stotal = eval(x[1])", " sused = eval(x[2])", " sfree = eval(x[3])", "", " memtotal = os.stat(\"/proc/kcore\")[stat.ST_SIZE]", "", " m = 1024*1024", " #print \"Memory RAM : %d MB (%d MB kernel, %d MB free)\" % (memtotal/m, (memtotal-total)/m, free/m)", " #print \" usage : %d MB shared %d MB buffers %d MB cached\" % (shared/m, buffers/m, cached/m)", " #print \"Swap area : %d MB (%d MB used)\" % (stotal/m, sused/m)", " info = {}", " info['mem_total'] = memtotal/m", " info['mem_kernel'] = (memtotal-total)/m", " info['mem_free'] = free/m", " info['swap_total'] = stotal/m", " info['swap_free'] = (stotal-sused)/m", " return info", "", " def load_avg():", " f = open(\"/proc/loadavg\")", " line = f.readline()", " field = string.split(line)", " info={}", " info['load_1'] = eval(field[0])", " info['load_5'] = eval(field[1])", " info['load_15'] = eval(field[2])", " return info", "", " def machine_info():", " all = load_avg()", " all.update(cpu_info())", " all.update(mem_info())", " all['long_name'] = long_machine_name", " all['name'] = machine_name", " return all", "", "", " uid_cache = {}", " gid_cache = {}", " def user_from_uid(uid):", " global uid_cache", " try:", " user = uid_cache[uid]", " except:", " user = pwd.getpwuid(uid)[0]", " uid_cache[uid] = user", " return user", "", " def group_from_gid(gid):", " global gid_cache", " try:", " group = gid_cache[gid]", " except:", " group = grp.getgrgid(gid)[0]", " gid_cache[gid] =group", " return group", "", " # Yes, this is slow. It also works and is pure Python (easy).", " # If your looking to do a real top, or fast ps command use SIWG to wrap the", " # ps and top code. This would give much better performance, be more robust,", " # and make the generally world a happier place. Please send it in when", " # your finished!", " # This is all pretty much stolen from readproc.c in the procps", " # package (scour the web).", "", " class process:", " def __init__(self,pid,seconds_since_boot=None,total_memory=None):", " self.info(int(pid),seconds_since_boot,total_memory)", " def info(self,pid,seconds_since_boot=None,total_memory=None):", " self.status2proc(pid)", " self.stat2proc(pid)", " self.statm2proc(pid)", " self.get_cmdline(pid)", " #self.get_environ(pid)", " if self.state == 'Z':", " self.cmd = self.cmd + \"\"", " self.beautify(seconds_since_boot,total_memory)", " self.pid = pid", " self.machine = machine_name", " self.long_machine = long_machine_name", " def status2proc(self,pid):", " f = open(\"/proc/%d/status\" % pid)", " lines = f.readlines()", " #line = map(string.split,lines)", " id = map(string.split,lines[4:6])", "", " #self.cmd = line[0][1]", " #self.state = line[1][2]", " self.ruid,self.euid,self.suid,self.fuid = map(int,id[0][1:])", " self.rgid,self.egid,self.sgid,self.fgid = map(int,id[1][1:])", " #self.euid = int(id[0][1])", " #self.egid = int(id[1][1])", " #self.vm_size = long(line[7][1])", " #self.vm_lock = long(line[8][1])", " #self.vm_rss = long(line[9][1])", " #self.vm_data = long(line[10][1])", " #self.vm_stack = long(line[11][1])", " #self.vm_exe = long(line[12][1])", " #self.vm_lib = long(line[13][1])", "", " #translate id's to user and group names", " #self.ruser = user_from_uid(self.ruid)", " #self.suser = user_from_uid(self.suid)", " self.euser = user_from_uid(self.euid)", " #self.fuser = user_from_uid(self.fuid)", " #self.rgroup = group_from_gid(self.rgid)", " #self.sgroup = group_from_gid(self.sgid)", " self.egroup = group_from_gid(self.egid)", " #self.fgroup = group_from_gid(self.fgid)", "", " def stat2proc(self,pid):", " # oh, to have sscanf... (I'm sure it is somewhere)", " f = open(\"/proc/%d/stat\" % pid)", " s = f.read(-1)", " f.close()", " cmd = string.rfind(s,'(') + 1", " begin = string.rfind(s,')')", " self.cmd = s[cmd:begin]", " begin = begin + 2", " field = string.split(s[begin:])", " self.state = field[0]", " self.ppid = int(field[1])", " #self.pgrp = int(field[2])", " #self.session = int(field[3])", " self.tty = int(field[4])", " #self.tpgid = eval(field[5])", " #self.flags = eval(field[6])", " #self.min_flt = long(field[7])", " #self.cmin_flt = long(field[8])", " #self.maj_flt = long(field[9])", " #self.cmaj_flt = long(field[10])", " self.utime = long(field[11])", " self.stime = long(field[12])", " self.cutime = int(field[13])", " self.cstime = int(field[14])", " self.priority = int(field[15])", " self.nice = int(field[16])", " #self.timeout = eval(field[17])", " #self.it_real_value = eval(field[18])", " self.start_time = long(field[19])", " self.vsize = long(field[20])", " self.rss = long(field[21])", " self.rss_rlim = long(field[22])", " #self.start_code = long(field[23])", " #self.end_code = long(field[24])", " self.start_stack = long(field[25])", " #self.kstk_esp = long(field[26])", " #self.kstk_eip = long(field[27])", " #self.wchan = long(field[29])", " #self.nswap = long(field[30])", " self.cnswap = long(field[31])", " if self.tty == 0: self.tty=-1", " def statm2proc(self,pid):", " f = open(\"/proc/%d/statm\" % pid)", " s = f.read(-1)", " f.close()", " field = string.split(s)", " self.size = int(field[0])", " self.resident = int(field[1])", " #self.share = int(field[2])", " #self.trs = int(field[3])", " #self.lrs = int(field[4])", " #self.drs = int(field[5])", " #self.dt = int(field[6])", " def get_cmdline(self,pid):", " f = open(\"/proc/%d/cmdline\" % pid)", " self.cmdline = f.read(-1)", " f.close()", " def get_environ(self,pid):", " f = open(\"/proc/%d/environ\" % pid)", " self.cmdline = f.read(-1)", " f.close()", "", " def beautify(self,seconds_since_boot=None,total_memory=None):", " \"\"\"* total_memory in MB", " *\"\"\"", " if seconds_since_boot is None:", " seconds_since_boot = uptime_info()['uptime']", " if total_memory is None:", " total_memory = mem_info()['mem_total']", " self.beautify_user()", " self.beautify_cpu(seconds_since_boot)", " self.beautify_memory(total_memory)", " self.beautify_state()", " def beautify_user(self):", " self.uid = self.euid", " self.user = self.euser", " self.gid = self.egid", " self.group = self.egroup", "", " def beautify_cpu(self,seconds_since_boot):", " include_dead_children = 0", " self.total_time = (self.utime + self.stime) / hertz", " self.wall_time = seconds_since_boot - self.start_time /hertz", " if include_dead_children:", " self.total_time = self.total_time + \\", " (self.cutime + self.cstime) / hertz", " self.pcpu = 0", " if self.wall_time:", " self.pcpu = self.total_time * 1000. / self.wall_time", " if self.pcpu > 999:", " self.pcpu = 999.", "", " self.cpu_percent = self.pcpu / 10.", " #foramt time into a days:hours:minutes:seconds string", " t = long(self.wall_time)", " t,ss = divmod(t,60)", " t,mm = divmod(t,60)", " t,hh = divmod(t,24)", " dd = t", " self.wall_time2 = \"%2d:%2d:%2d:%2d\" % (dd,hh,mm,ss)", " t = long(self.total_time)", " t,ss = divmod(t,60)", " t,mm = divmod(t,60)", " t,hh = divmod(t,24)", " dd = t", " self.total_time2 = \"%2d:%2d:%2d:%2d\" % (dd,hh,mm,ss)", "", " def beautify_memory(self,total_memory):", " \"\"\"* translate memory values to MB, and percentage", " *\"\"\"", " self.total_memory = self.size * 4 / 1024.", " self.resident_memory = self.resident * 4/ 1024.", " self.memory_percent = self.resident_memory / total_memory * 100", " def beautify_state(self):", " self.condition= states[self.state]", " self.cmdline = string.replace(self.cmdline,'\\x00',' ')", " self.cmdline = string.strip(self.cmdline)", "", " #ps_default = ['user','pid','cpu_percent','total_memory','resident_memory',", " # 'state','start_time','cmdline']", " ps_default = ['user','pid','cpu_percent','total_memory','resident_memory',", " 'state','total2_time','cmdline']", " def labels(self):", " s = \"%-8s %5s %4s %4s %8s %8s %1s %10s %3s\" % \\", " ('USER','PID','%CPU', '%MEM', 'TOTAL MB', ' RES MB',", " 'ST', 'RT-D:H:M:S', 'CMD')", " return s", " def labels_with_name(self):", " s = \"%-6s %s\" % ('MACHINE',self.labels())", " return s", " def str_with_name(self):", " s = \"%-6s %-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\", " (self.machine[-6:], self.user,self.pid,self.cpu_percent,", " self.memory_percent, self.total_memory, self.resident_memory,", " self.state, self.total_time2)", " bytes_left = 80 - len(s) - 1", " if len(self.cmdline) > bytes_left:", " s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]", " else:", " s = s + self.cmdline", " return s", " def __str__(self):", " s = \"%-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\", " (self.user,self.pid,self.cpu_percent,self.memory_percent,", " self.total_memory, self.resident_memory, self.state,", " self.total_time2)", " bytes_left = 80 - len(s) - 1", " if len(self.cmdline) > bytes_left:", " s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]", " else:", " s = s + self.cmdline", " return", "", "", " def ps_list(sort_by='cpu',**filters):", " import os, glob", " current = os.path.abspath('.')", " os.chdir('/proc')", " procs = glob.glob('[0-9]*')", " results = []", " seconds_since_boot = uptime_info()['uptime']", " total_memory = mem_info()['mem_total']", " for proc in procs:", " results.append(process(proc,seconds_since_boot,total_memory))", " os.chdir(current)", " return ps_sort(results,sort_by,**filters)", " # end linux specific", "else:", " # punt. At least there exist a class so that unpickling won't fail.", " def uptime_info():", " raise NotImplemented, 'not implemented on this architecture'", " def cpu_info():", " raise NotImplemented, 'not implemented on this architecture'", " def filter_name(name):", " raise NotImplemented, 'not implemented on this architecture'", " def mem_info():", " raise NotImplemented, 'not implemented on this architecture'", " def load_avg():", " raise NotImplemented, 'not implemented on this architecture'", " def machine_info():", " raise NotImplemented, 'not implemented on this architecture'", "", " uid_cache = {}", " gid_cache = {}", " def user_from_uid(uid):", " raise NotImplemented, 'not implemented on this architecture'", " def group_from_gid(gid):", " raise NotImplemented, 'not implemented on this architecture'", " def ps_list(sort_by='cpu',**filters):", " raise NotImplemented, 'not implemented on this architecture'", " class process:", " def labels(self):", " s = \"%-8s %5s %4s %4s %8s %8s %1s %10s %3s\" % \\", " ('USER','PID','%CPU', '%MEM', 'TOTAL MB', ' RES MB',", " 'ST', 'RT-D:H:M:S', 'CMD')", " return s", " def labels_with_name(self):", " s = \"%-6s %s\" % ('MACHINE',self.labels())", " return s", " def str_with_name(self):", " s = \"%-6s %-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\", " (self.machine[-6:], self.user,self.pid,self.cpu_percent,", " self.memory_percent, self.total_memory, self.resident_memory,", " self.state, self.total_time2)", " bytes_left = 80 - len(s) - 1", " if len(self.cmdline) > bytes_left:", " s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]", " else:", " s = s + self.cmdline", " return s", "", " def __str__(self):", " s = \"%-8s %5d %4.1f %4.1f %8.3f %8.3f %1s %s \" % \\", " (self.user,self.pid,self.cpu_percent,self.memory_percent,", " self.total_memory, self.resident_memory, self.state,", " self.total_time2)", " bytes_left = 80 - len(s) - 1", " if len(self.cmdline) > bytes_left:", " s = s + self.cmdline[:6] + '...' + self.cmdline[-(bytes_left-9):]", " else:", " s = s + self.cmdline", " return", "", "# these are all general to any OS", "", "def cmp_pid(x,y):", " return cmp(x.pid,y.pid)", "def cmp_cpu(x,y):", " return -cmp(x.cpu_percent,y.cpu_percent)", "def cmp_user(x,y):", " return cmp(x.user,y.user)", "def cmp_machine(x,y):", " return cmp(x.machine,y.machine)", "def cmp_memory(x,y):", " return -cmp(x.memory_percent,y.memory_percent)", "def cmp_state(x,y):", " return cmp(x.state,y.state)", "def cmp_command(x,y):", " return cmp(x.cmdline,y.cmdline)", "", "ps_cmp={}", "ps_cmp['pid'] = cmp_pid", "ps_cmp['cpu'] = cmp_cpu", "ps_cmp['user'] = cmp_user", "ps_cmp['machine'] = cmp_machine", "ps_cmp['memory'] = cmp_memory", "ps_cmp['state'] = cmp_state", "ps_cmp['command'] = cmp_command", "", "from fnmatch import fnmatch", "", "def filter_machine(x,filt):", " return (fnmatch(x.machine,filt) or fnmatch(x.long_machine,filt))", "def filter_user(x,filt):", " return (fnmatch(x.user,filt))", "def filter_state(x,filt):", " return (fnmatch(x.state,filt))", "def filter_command(x,filt):", " return (fnmatch(x.cmdline,filt))", "def filter_cpu(x,filt):", " return eval(str(x.cpu_percent) + filt)", "def filter_memory(x,filt):", " return eval(str(x.memory_percent) + filt)", "def filter_mb(x,filt):", " return eval(str(x.total_memory) + filt)", "", "ps_filter={}", "ps_filter['user'] = filter_user", "ps_filter['machine'] = filter_machine", "ps_filter['state'] = filter_state", "ps_filter['command'] = filter_command", "ps_filter['memory'] = filter_memory", "ps_filter['mb'] = filter_mb", "ps_filter['cpu'] = filter_cpu", "", "def ps(sort_by='cpu',**filters):", " psl = ps_list(sort_by,**filters)", " if len(psl):", " print psl[0].labels_with_name()", " for i in psl:", " print i", "", "def ps_sort(psl,sort_by='cpu',**filters):", " for f in filters.keys():", " try:", " filt = ps_filter[f]", " filt_str = filters[f]", " psl = filter(lambda x,filt=filt,y=filt_str:filt(x,y),psl)", " except KeyError:", " print 'warning: \"', f, '\"is an invalid key for filtering command.'", " print ' ', 'use one of the following:', str(ps_filter.keys())", " try:", " compare = ps_cmp[sort_by]", " psl.sort(compare)", " except KeyError:", " print 'warning: \"', sort_by, '\"is an invalid choice for sorting.'", " print ' ', 'use one of the following:', str(ps_cmp.keys())", " return psl", "", "" ], "deleted": [] } } ] }, { "hash": "d1ed079cec3a71e04a867db965061920c1b1d16f", "msg": "Support for getting packages from non-package subdirectories.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-13T11:53:17+00:00", "author_timezone": 0, "committer_date": "2004-05-13T11:53:17+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "b7cc0ff045f99119e08a54aab09abc54487384ee" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 8, "insertions": 11, "lines": 19, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/examples/setup_module_pure_super.py", "new_path": "scipy_distutils/examples/setup_module_pure_super.py", "filename": "setup_module_pure_super.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,5 @@\n #!/usr/bin/env python\n+from os.path import join\n from scipy_distutils.core import setup\n from scipy_distutils.misc_util import default_config_dict, get_path, \\\n merge_config_dicts, get_subpackages\n", "added_lines": 1, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\nfrom os.path import join\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict, get_path, \\\n merge_config_dicts, get_subpackages\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n\n local_path = get_path(__name__,parent_path)\n install_path = join(*config['name'].split('.'))\n\n config_list = [config]\n\n config_list += get_subpackages(local_path,\n parent=config['name'],\n parent_path=parent_path,\n include_packages = ['subpackage1','subpackage2']\n )\n\n config = merge_config_dicts(config_list)\n\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "source_code_before": "#!/usr/bin/env python\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict, get_path, \\\n merge_config_dicts, get_subpackages\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n\n local_path = get_path(__name__,parent_path)\n install_path = join(*config['name'].split('.'))\n\n config_list = [config]\n\n config_list += get_subpackages(local_path,\n parent=config['name'],\n parent_path=parent_path,\n include_packages = ['subpackage1','subpackage2']\n )\n\n config = merge_config_dicts(config_list)\n\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure_super.py", "nloc": 13, "complexity": 1, "token_count": 83, "parameters": [ "parent_package", "parent_path" ], "start_line": 7, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 } ], "methods_before": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_pure_super.py", "nloc": 13, "complexity": 1, "token_count": 83, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 19, "complexity": 1, "token_count": 124, "diff_parsed": { "added": [ "from os.path import join" ], "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": "@@ -477,24 +477,26 @@ def get_subpackages(path,\n \n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n- setup_file = os.path.join(dirname,\\\n- 'setup_' + package_name.split('.')[-1]+'.py')\n+ name = package_name.split('.')[-1]\n+ setup_name = 'setup_' + name\n+ setup_file = os.path.join(dirname, setup_name + '.py')\n+ ns = package_name.split('.')[:-1]\n+ if parent: ns.insert(0, parent)\n+ parent_name = '.'.join(ns)\n+\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n \n- config = default_config_dict(package_name, parent or '',\n+ config = default_config_dict(name, parent_name,\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n- exec 'import setup_%s as setup_module' % (package_name)\n- if not parent:\n- args = ('',)\n- else:\n- args = (parent,)\n+ exec 'import %s as setup_module' % (setup_name)\n+ args = (parent_name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n", "added_lines": 10, "deleted_lines": 8, "source_code": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_build_platlib():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','lib'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n name = package_name.split('.')[-1]\n setup_name = 'setup_' + name\n setup_file = os.path.join(dirname, setup_name + '.py')\n ns = package_name.split('.')[:-1]\n if parent: ns.insert(0, parent)\n parent_name = '.'.join(ns)\n\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(name, parent_name,\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import %s as setup_module' % (setup_name)\n args = (parent_name,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "\nimport os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d or '.'\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n if not d: continue\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n if not d: continue\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\ndef get_build_platlib():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','lib'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_dirs_with_init((packages,path), dirname, names):\n \"\"\"Internal: used by get_subpackages.\"\"\"\n for bad in ['.svn','build']:\n if bad in names:\n del names[names.index(bad)]\n if os.path.isfile(os.path.join(dirname,'__init__.py')):\n if path==dirname: return\n package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])\n if package_name not in packages:\n packages.append(package_name)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[],\n include_only=None,\n recursive=None):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n\n When include_only is True then only configurations of those\n packages are returned that are in include_packages list.\n\n If recursive is True then subpackages are searched recursively\n starting from the path and added to include_packages list.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n if include_only and package_name not in include_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n if recursive:\n os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n\n for package_name in include_packages:\n dirname = os.path.join(*([path]+package_name.split('.')))\n setup_file = os.path.join(dirname,\\\n 'setup_' + package_name.split('.')[-1]+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\ndef generate_config_py(extension, build_dir):\n \"\"\" Generate /config.py file containing system_info\n information used during building the package.\n\n Usage:\\\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n \"\"\"\n from scipy_distutils.system_info import system_info\n from distutils.dir_util import mkpath\n target = os.path.join(*([build_dir]+extension.name.split('.'))) + '.py'\n mkpath(os.path.dirname(target))\n f = open(target,'w')\n f.write('# This file is generated by %s\\n' % (os.path.abspath(sys.argv[0])))\n f.write('# It contains system_info results at the time of building this package.\\n')\n f.write('__all__ = [\"get_info\",\"show\"]\\n\\n')\n for k,i in system_info.saved_results.items():\n f.write('%s=%r\\n' % (k,i))\n f.write('\\ndef get_info(name): g=globals(); return g.get(name,g.get(name+\"_info\",{}))\\n')\n f.write('''\ndef show():\n for name,info_dict in globals().items():\n if name[0]==\"_\" or type(info_dict) is not type({}): continue\n print name+\":\"\n if not info_dict:\n print \" NOT AVAILABLE\"\n for k,v in info_dict.items():\n v = str(v)\n if k==\\'sources\\' and len(v)>200: v = v[:60]+\\' ...\\\\n... \\'+v[-60:]\n print \\' %s = %s\\'%(k,v)\n print\n return\n ''')\n\n f.close()\n return target\n\ndef generate_svn_version_py(extension, build_dir):\n \"\"\" Generate __svn_version__.py file containing SVN\n revision number of a module.\n \n To use, add the following codelet to setup\n configuration(..) function\n\n ext = Extension(dot_join(config['name'],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n \"\"\"\n from distutils import dep_util\n local_path = extension.local_path\n target = os.path.join(build_dir, '__svn_version__.py')\n entries = os.path.join(local_path,'.svn','entries')\n if os.path.isfile(entries):\n if not dep_util.newer(entries, target):\n return target\n elif os.path.isfile(target):\n return target\n\n revision = get_svn_revision(local_path)\n f = open(target,'w')\n f.write('revision=%s\\n' % (revision))\n f.close()\n return target\n\ndef get_svn_revision(path):\n \"\"\" Return path's SVN revision number.\n \"\"\"\n entries = os.path.join(path,'.svn','entries')\n revision = None\n if os.path.isfile(entries):\n f = open(entries)\n m = re.search(r'revision=\"(?P\\d+)\"',f.read())\n f.close()\n if m:\n revision = int(m.group('revision'))\n return revision\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "get_build_platlib", "long_name": "get_build_platlib( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 250, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 264, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 277, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 279, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 291, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 300, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 304, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 306, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 316, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 334, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 341, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 348, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 355, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 377, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 397, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 62, "complexity": 17, "token_count": 470, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 408, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 508, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 109, "parameters": [ "extension", "build_dir" ], "start_line": 546, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 575, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 14, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 60, "end_line": 62, "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": 63, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 6, "token_count": 126, "parameters": [ "mod_name", "parent_path" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 87, "end_line": 89, "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": 91, "end_line": 94, "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": 96, "end_line": 97, "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": 99, "end_line": 113, "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": 115, "end_line": 125, "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": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 146, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 187, "end_line": 194, "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": 15, "complexity": 8, "token_count": 99, "parameters": [ "config_list" ], "start_line": 196, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 212, "end_line": 217, "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": 219, "end_line": 220, "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": 222, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 239, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 245, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "get_build_platlib", "long_name": "get_build_platlib( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 250, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 264, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 277, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 279, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 291, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 300, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 304, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 306, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 316, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 334, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 341, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 348, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 355, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 377, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "_get_dirs_with_init", "long_name": "_get_dirs_with_init( ( packages , path )", "filename": "misc_util.py", "nloc": 10, "complexity": 6, "token_count": 104, "parameters": [ "packages", "path" ], "start_line": 397, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 61, "complexity": 18, "token_count": 447, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 408, "end_line": 504, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "generate_config_py", "long_name": "generate_config_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 28, "complexity": 2, "token_count": 143, "parameters": [ "extension", "build_dir" ], "start_line": 506, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "generate_svn_version_py", "long_name": "generate_svn_version_py( extension , build_dir )", "filename": "misc_util.py", "nloc": 15, "complexity": 4, "token_count": 109, "parameters": [ "extension", "build_dir" ], "start_line": 544, "end_line": 571, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_svn_revision", "long_name": "get_svn_revision( path )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 75, "parameters": [ "path" ], "start_line": 573, "end_line": 584, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] , include_only = None , recursive = None )", "filename": "misc_util.py", "nloc": 62, "complexity": 17, "token_count": 470, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages", "include_only", "recursive" ], "start_line": 408, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 } ], "nloc": 426, "complexity": 135, "token_count": 3113, "diff_parsed": { "added": [ " name = package_name.split('.')[-1]", " setup_name = 'setup_' + name", " setup_file = os.path.join(dirname, setup_name + '.py')", " ns = package_name.split('.')[:-1]", " if parent: ns.insert(0, parent)", " parent_name = '.'.join(ns)", "", " config = default_config_dict(name, parent_name,", " exec 'import %s as setup_module' % (setup_name)", " args = (parent_name,)" ], "deleted": [ " setup_file = os.path.join(dirname,\\", " 'setup_' + package_name.split('.')[-1]+'.py')", " config = default_config_dict(package_name, parent or '',", " exec 'import setup_%s as setup_module' % (package_name)", " if not parent:", " args = ('',)", " else:", " args = (parent,)" ] } } ] }, { "hash": "758a1c8fc7e08b1b62d4efc961445d57925065e7", "msg": "Fixed target_dir of pure Fortran extensions to include extension names.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-13T13:01:00+00:00", "author_timezone": 0, "committer_date": "2004-05-13T13:01:00+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d1ed079cec3a71e04a867db965061920c1b1d16f" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 1, "insertions": 4, "lines": 5, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_src.py", "new_path": "scipy_distutils/command/build_src.py", "filename": "build_src.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -274,7 +274,10 @@ def f2py_sources(self, sources, extension):\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n- target_dir = self.build_src\n+ if type(extension) is type(()): name = extension[0]\n+ else: name = extension.name\n+ target_dir = os.path.join(*([self.build_src]\\\n+ +name.split('.')[:-1]))\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n", "added_lines": 4, "deleted_lines": 1, "source_code": "\"\"\" Build swig, f2py, weave, sources.\n\"\"\"\n\nimport os\nimport re\n\nfrom distutils.cmd import Command\nfrom distutils.command import build_ext, build_py\nfrom distutils.util import convert_path\nfrom distutils.dep_util import newer_group, newer\n\nfrom scipy_distutils import log\nfrom scipy_distutils.misc_util import fortran_ext_match, all_strings\nfrom scipy_distutils.from_template import process_str\n\nclass build_src(build_ext.build_ext):\n\n description = \"build sources from SWIG, F2PY files or a function\"\n\n user_options = [\n ('build-src=', 'd', \"directory to \\\"build\\\" sources to\"),\n ('f2pyflags=', None, \"additonal flags to f2py\"),\n ('swigflags=', None, \"additional flags to swig\"),\n ('force', 'f', \"forcibly build everything (ignore file timestamps)\"),\n ('inplace', 'i',\n \"ignore build-lib and put compiled extensions into the source \" +\n \"directory alongside your pure Python modules\"),\n ]\n\n boolean_options = ['force','inplace']\n\n help_options = []\n\n def initialize_options(self):\n self.extensions = None\n self.package = None\n self.py_modules = None\n self.build_src = None\n self.build_lib = None\n self.build_base = None\n self.force = None\n self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n return\n\n def finalize_options(self):\n self.set_undefined_options('build',\n ('build_base', 'build_base'),\n ('build_lib', 'build_lib'),\n ('force', 'force'))\n if self.package is None:\n self.package = self.distribution.ext_package\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules\n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n if self.inplace is None:\n build_ext = self.get_finalized_command('build_ext')\n self.inplace = build_ext.inplace\n\n # py_modules is used in build_py.find_package_modules\n self.py_modules = {}\n\n if self.f2pyflags is None:\n self.f2pyflags = []\n else:\n self.f2pyflags = self.f2pyflags.split() # XXX spaces??\n\n if self.swigflags is None:\n self.swigflags = []\n else:\n self.swigflags = self.swigflags.split() # XXX spaces??\n return\n\n def run(self):\n if not (self.extensions or self.libraries):\n return\n self.build_sources()\n return\n\n def build_sources(self):\n self.check_extensions_list(self.extensions)\n\n for ext in self.extensions:\n self.build_extension_sources(ext)\n\n for libname_info in self.libraries:\n self.build_library_sources(*libname_info)\n\n return\n\n def build_library_sources(self, lib_name, build_info):\n sources = list(build_info.get('sources',[]))\n\n if not sources:\n return\n\n log.info('building library \"%s\" sources' % (lib_name))\n\n sources = self.generate_sources(sources, (lib_name, build_info))\n\n build_info['sources'] = sources\n return\n\n def build_extension_sources(self, ext):\n sources = list(ext.sources)\n\n log.info('building extension \"%s\" sources' % (ext.name))\n\n fullname = self.get_ext_fullname(ext.name)\n\n modpath = fullname.split('.')\n package = '.'.join(modpath[0:-1])\n\n if self.inplace:\n build_py = self.get_finalized_command('build_py')\n self.ext_target_dir = build_py.get_package_dir(package)\n\n sources = self.generate_sources(sources, ext)\n\n sources = self.template_sources(sources, ext)\n \n sources = self.swig_sources(sources, ext)\n\n sources = self.f2py_sources(sources, ext)\n\n sources, py_files = self.filter_py_files(sources)\n\n if not self.py_modules.has_key(package):\n self.py_modules[package] = []\n modules = []\n for f in py_files:\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n self.py_modules[package] += modules\n\n ext.sources = sources\n return\n\n def generate_sources(self, sources, extension):\n new_sources = []\n func_sources = []\n for source in sources:\n if type(source) is type(''):\n new_sources.append(source)\n else:\n func_sources.append(source)\n if not func_sources:\n return new_sources\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n if type(extension) is type(()):\n name = extension[0]\n else:\n name = extension.name\n build_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n if type(source) is type([]):\n [log.info(\" adding '%s' to sources.\" % (s)) for s in source]\n new_sources.extend(source)\n else:\n log.info(\" adding '%s' to sources.\" % (source))\n new_sources.append(source)\n return new_sources\n\n def filter_py_files(self, sources):\n new_sources = []\n py_files = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext=='.py': \n py_files.append(source)\n else:\n new_sources.append(source)\n return new_sources, py_files\n\n def template_sources(self, sources, extension):\n new_sources = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.src': # Template file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n self.mkpath(target_dir)\n target_file = os.path.join(target_dir,os.path.basename(base))\n if (self.force or newer(source, target_file)):\n fid = open(source)\n outstr = process_str(fid.read())\n fid.close()\n fid = open(target_file,'w')\n fid.write(outstr)\n fid.close()\n new_sources.append(target_file)\n else:\n new_sources.append(source)\n return new_sources \n \n def f2py_sources(self, sources, extension):\n new_sources = []\n f2py_sources = []\n f_sources = []\n f2py_targets = {}\n target_dirs = []\n ext_name = extension.name.split('.')[-1]\n skip_f2py = 0\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.pyf': # F2PY interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n if os.path.isfile(source):\n name = get_f2py_modulename(source)\n assert name==ext_name,'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name`\n target_file = os.path.join(target_dir,name+'module.c')\n else:\n log.debug(' source %s does not exist: skipping f2py\\'ing.' \\\n % (source))\n name = ext_name\n skip_f2py = 1\n target_file = os.path.join(target_dir,name+'module.c')\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %smodule.c was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = os.path.join(target_dir,name+'module.c')\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n new_sources.append(target_file)\n elif fortran_ext_match(ext):\n f_sources.append(source)\n else:\n new_sources.append(source)\n\n if not (f2py_sources or f_sources):\n return new_sources\n\n map(self.mkpath, target_dirs)\n\n f2py_options = extension.f2py_options + self.f2pyflags\n if f2py_sources:\n assert len(f2py_sources)==1,\\\n 'only one .pyf file is allowed per extension module but got'\\\n ' more:'+`f2py_sources`\n source = f2py_sources[0]\n target_file = f2py_targets[source]\n target_dir = os.path.dirname(target_file)\n depends = [source] + extension.depends\n if (self.force or newer_group(depends, target_file,'newer')) \\\n and not skip_f2py:\n log.info(\"f2py: %s\" % (source))\n import f2py2e\n f2py2e.run_main(f2py_options + ['--build-dir',target_dir,source])\n else:\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n if type(extension) is type(()): name = extension[0]\n else: name = extension.name\n target_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n if (self.force or newer_group(depends, target_file, 'newer')) \\\n and not skip_f2py:\n import f2py2e\n log.info(\"f2py:> %s\" % (target_file))\n self.mkpath(target_dir)\n f2py2e.run_main(f2py_options + ['--lower',\n '--build-dir',target_dir]+\\\n ['-m',ext_name]+f_sources)\n else:\n log.debug(\" skipping f2py fortran files for '%s' (up-to-date)\"\\\n % (target_file))\n\n assert os.path.isfile(target_file),`target_file`+' missing'\n\n target_c = os.path.join(self.build_src,'fortranobject.c')\n target_h = os.path.join(self.build_src,'fortranobject.h')\n log.info(\" adding '%s' to sources.\" % (target_c))\n new_sources.append(target_c)\n if self.build_src not in extension.include_dirs:\n log.info(\" adding '%s' to include_dirs.\" \\\n % (self.build_src))\n extension.include_dirs.append(self.build_src)\n\n if not skip_f2py:\n import f2py2e\n d = os.path.dirname(f2py2e.__file__)\n source_c = os.path.join(d,'src','fortranobject.c')\n source_h = os.path.join(d,'src','fortranobject.h')\n if newer(source_c,target_c) or newer(source_h,target_h):\n self.mkpath(os.path.dirname(target_c))\n self.copy_file(source_c,target_c)\n self.copy_file(source_h,target_h)\n else:\n assert os.path.isfile(target_c),`target_c` + ' missing'\n assert os.path.isfile(target_h),`target_h` + ' missing'\n \n for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']:\n filename = os.path.join(target_dir,ext_name + name_ext)\n if os.path.isfile(filename):\n log.info(\" adding '%s' to sources.\" % (filename))\n f_sources.append(filename)\n\n return new_sources + f_sources\n\n def swig_sources(self, sources, extension):\n new_sources = []\n swig_sources = []\n swig_targets = {}\n target_dirs = []\n py_files = [] # swig generated .py files\n target_ext = '.c'\n typ = None\n is_cpp = 0\n skip_swig = 0\n ext_name = extension.name.split('.')[-1]\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.i': # SWIG interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n py_target_dir = self.ext_target_dir\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n py_target_dir = target_dir\n if os.path.isfile(source):\n name = get_swig_modulename(source)\n assert name==ext_name[1:],'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name[1:]`\n if typ is None:\n typ = get_swig_target(source)\n is_cpp = typ=='c++'\n if is_cpp:\n target_ext = '.cpp'\n else:\n assert typ == get_swig_target(source),`typ`\n target_file = os.path.join(target_dir,'%s_wrap%s' \\\n % (name, target_ext))\n else:\n log.debug(' source %s does not exist: skipping swig\\'ing.' \\\n % (source))\n name = ext_name[1:]\n skip_swig = 1\n target_file = _find_swig_target(target_dir, name)\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %s_wrap.{c,cpp} was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = _find_swig_target(target_dir, name)\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n py_files.append(os.path.join(py_target_dir, name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n else:\n new_sources.append(source)\n\n if not swig_sources:\n return new_sources\n\n if skip_swig:\n return new_sources + py_files\n\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n if is_cpp:\n swig_cmd.append('-c++')\n for d in extension.include_dirs:\n swig_cmd.append('-I'+d)\n for source in swig_sources:\n target = swig_targets[source]\n depends = [source] + extension.depends\n if self.force or newer_group(depends, target, 'newer'):\n log.info(\"%s: %s\" % (os.path.basename(swig) \\\n + (is_cpp and '++' or ''), source))\n self.spawn(swig_cmd + self.swigflags \\\n + [\"-o\", target, '-outdir', py_target_dir, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\n\ndef appendpath(prefix,path):\n if os.path.isabs(path):\n absprefix = os.path.abspath(prefix)\n d = os.path.commonprefix([absprefix,path])\n subpath = path[len(d):]\n assert not os.path.isabs(subpath),`subpath`\n return os.path.join(prefix,subpath)\n return os.path.join(prefix, path)\n\n#### SWIG related auxiliary functions ####\n_swig_module_name_match = re.compile(r'\\s*%module\\s*(?P[\\w_]+)',\n re.I).match\n_has_c_header = re.compile(r'-[*]-\\s*c\\s*-[*]-',re.I).search\n_has_cpp_header = re.compile(r'-[*]-\\s*c[+][+]\\s*-[*]-',re.I).search\n\ndef get_swig_target(source):\n f = open(source,'r')\n result = 'c'\n line = f.readline()\n if _has_cpp_header(line):\n result = 'c++'\n if _has_c_header(line):\n result = 'c'\n f.close()\n return result\n\ndef get_swig_modulename(source):\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _swig_module_name_match(line)\n if m:\n name = m.group('name')\n break\n f.close()\n return name\n\ndef _find_swig_target(target_dir,name):\n for ext in ['.cpp','.c']:\n target = os.path.join(target_dir,'%s_wrap%s' % (name, ext))\n if os.path.isfile(target):\n break\n return target\n\n#### F2PY related auxiliary functions ####\n\n_f2py_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',\n re.I).match\n_f2py_user_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?'\\\n '__user__[\\w_]*)',re.I).match\n\ndef get_f2py_modulename(source):\n name = None\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _f2py_module_name_match(line)\n if m:\n if _f2py_user_module_name_match(line): # skip *__user__* names\n continue\n name = m.group('name')\n break\n f.close()\n return name\n\n##########################################\n", "source_code_before": "\"\"\" Build swig, f2py, weave, sources.\n\"\"\"\n\nimport os\nimport re\n\nfrom distutils.cmd import Command\nfrom distutils.command import build_ext, build_py\nfrom distutils.util import convert_path\nfrom distutils.dep_util import newer_group, newer\n\nfrom scipy_distutils import log\nfrom scipy_distutils.misc_util import fortran_ext_match, all_strings\nfrom scipy_distutils.from_template import process_str\n\nclass build_src(build_ext.build_ext):\n\n description = \"build sources from SWIG, F2PY files or a function\"\n\n user_options = [\n ('build-src=', 'd', \"directory to \\\"build\\\" sources to\"),\n ('f2pyflags=', None, \"additonal flags to f2py\"),\n ('swigflags=', None, \"additional flags to swig\"),\n ('force', 'f', \"forcibly build everything (ignore file timestamps)\"),\n ('inplace', 'i',\n \"ignore build-lib and put compiled extensions into the source \" +\n \"directory alongside your pure Python modules\"),\n ]\n\n boolean_options = ['force','inplace']\n\n help_options = []\n\n def initialize_options(self):\n self.extensions = None\n self.package = None\n self.py_modules = None\n self.build_src = None\n self.build_lib = None\n self.build_base = None\n self.force = None\n self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n return\n\n def finalize_options(self):\n self.set_undefined_options('build',\n ('build_base', 'build_base'),\n ('build_lib', 'build_lib'),\n ('force', 'force'))\n if self.package is None:\n self.package = self.distribution.ext_package\n self.extensions = self.distribution.ext_modules\n self.libraries = self.distribution.libraries or []\n self.py_modules = self.distribution.py_modules\n if self.build_src is None:\n self.build_src = os.path.join(self.build_base, 'src')\n if self.inplace is None:\n build_ext = self.get_finalized_command('build_ext')\n self.inplace = build_ext.inplace\n\n # py_modules is used in build_py.find_package_modules\n self.py_modules = {}\n\n if self.f2pyflags is None:\n self.f2pyflags = []\n else:\n self.f2pyflags = self.f2pyflags.split() # XXX spaces??\n\n if self.swigflags is None:\n self.swigflags = []\n else:\n self.swigflags = self.swigflags.split() # XXX spaces??\n return\n\n def run(self):\n if not (self.extensions or self.libraries):\n return\n self.build_sources()\n return\n\n def build_sources(self):\n self.check_extensions_list(self.extensions)\n\n for ext in self.extensions:\n self.build_extension_sources(ext)\n\n for libname_info in self.libraries:\n self.build_library_sources(*libname_info)\n\n return\n\n def build_library_sources(self, lib_name, build_info):\n sources = list(build_info.get('sources',[]))\n\n if not sources:\n return\n\n log.info('building library \"%s\" sources' % (lib_name))\n\n sources = self.generate_sources(sources, (lib_name, build_info))\n\n build_info['sources'] = sources\n return\n\n def build_extension_sources(self, ext):\n sources = list(ext.sources)\n\n log.info('building extension \"%s\" sources' % (ext.name))\n\n fullname = self.get_ext_fullname(ext.name)\n\n modpath = fullname.split('.')\n package = '.'.join(modpath[0:-1])\n\n if self.inplace:\n build_py = self.get_finalized_command('build_py')\n self.ext_target_dir = build_py.get_package_dir(package)\n\n sources = self.generate_sources(sources, ext)\n\n sources = self.template_sources(sources, ext)\n \n sources = self.swig_sources(sources, ext)\n\n sources = self.f2py_sources(sources, ext)\n\n sources, py_files = self.filter_py_files(sources)\n\n if not self.py_modules.has_key(package):\n self.py_modules[package] = []\n modules = []\n for f in py_files:\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n self.py_modules[package] += modules\n\n ext.sources = sources\n return\n\n def generate_sources(self, sources, extension):\n new_sources = []\n func_sources = []\n for source in sources:\n if type(source) is type(''):\n new_sources.append(source)\n else:\n func_sources.append(source)\n if not func_sources:\n return new_sources\n if self.inplace:\n build_dir = self.ext_target_dir\n else:\n if type(extension) is type(()):\n name = extension[0]\n else:\n name = extension.name\n build_dir = os.path.join(*([self.build_src]\\\n +name.split('.')[:-1]))\n self.mkpath(build_dir)\n for func in func_sources:\n source = func(extension, build_dir)\n if type(source) is type([]):\n [log.info(\" adding '%s' to sources.\" % (s)) for s in source]\n new_sources.extend(source)\n else:\n log.info(\" adding '%s' to sources.\" % (source))\n new_sources.append(source)\n return new_sources\n\n def filter_py_files(self, sources):\n new_sources = []\n py_files = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext=='.py': \n py_files.append(source)\n else:\n new_sources.append(source)\n return new_sources, py_files\n\n def template_sources(self, sources, extension):\n new_sources = []\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.src': # Template file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n self.mkpath(target_dir)\n target_file = os.path.join(target_dir,os.path.basename(base))\n if (self.force or newer(source, target_file)):\n fid = open(source)\n outstr = process_str(fid.read())\n fid.close()\n fid = open(target_file,'w')\n fid.write(outstr)\n fid.close()\n new_sources.append(target_file)\n else:\n new_sources.append(source)\n return new_sources \n \n def f2py_sources(self, sources, extension):\n new_sources = []\n f2py_sources = []\n f_sources = []\n f2py_targets = {}\n target_dirs = []\n ext_name = extension.name.split('.')[-1]\n skip_f2py = 0\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.pyf': # F2PY interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n if os.path.isfile(source):\n name = get_f2py_modulename(source)\n assert name==ext_name,'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name`\n target_file = os.path.join(target_dir,name+'module.c')\n else:\n log.debug(' source %s does not exist: skipping f2py\\'ing.' \\\n % (source))\n name = ext_name\n skip_f2py = 1\n target_file = os.path.join(target_dir,name+'module.c')\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %smodule.c was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = os.path.join(target_dir,name+'module.c')\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n new_sources.append(target_file)\n elif fortran_ext_match(ext):\n f_sources.append(source)\n else:\n new_sources.append(source)\n\n if not (f2py_sources or f_sources):\n return new_sources\n\n map(self.mkpath, target_dirs)\n\n f2py_options = extension.f2py_options + self.f2pyflags\n if f2py_sources:\n assert len(f2py_sources)==1,\\\n 'only one .pyf file is allowed per extension module but got'\\\n ' more:'+`f2py_sources`\n source = f2py_sources[0]\n target_file = f2py_targets[source]\n target_dir = os.path.dirname(target_file)\n depends = [source] + extension.depends\n if (self.force or newer_group(depends, target_file,'newer')) \\\n and not skip_f2py:\n log.info(\"f2py: %s\" % (source))\n import f2py2e\n f2py2e.run_main(f2py_options + ['--build-dir',target_dir,source])\n else:\n log.debug(\" skipping '%s' f2py interface (up-to-date)\" % (source))\n else:\n #XXX TODO: --inplace support for sdist command\n target_dir = self.build_src\n target_file = os.path.join(target_dir,ext_name + 'module.c')\n new_sources.append(target_file)\n depends = f_sources + extension.depends\n if (self.force or newer_group(depends, target_file, 'newer')) \\\n and not skip_f2py:\n import f2py2e\n log.info(\"f2py:> %s\" % (target_file))\n self.mkpath(target_dir)\n f2py2e.run_main(f2py_options + ['--lower',\n '--build-dir',target_dir]+\\\n ['-m',ext_name]+f_sources)\n else:\n log.debug(\" skipping f2py fortran files for '%s' (up-to-date)\"\\\n % (target_file))\n\n assert os.path.isfile(target_file),`target_file`+' missing'\n\n target_c = os.path.join(self.build_src,'fortranobject.c')\n target_h = os.path.join(self.build_src,'fortranobject.h')\n log.info(\" adding '%s' to sources.\" % (target_c))\n new_sources.append(target_c)\n if self.build_src not in extension.include_dirs:\n log.info(\" adding '%s' to include_dirs.\" \\\n % (self.build_src))\n extension.include_dirs.append(self.build_src)\n\n if not skip_f2py:\n import f2py2e\n d = os.path.dirname(f2py2e.__file__)\n source_c = os.path.join(d,'src','fortranobject.c')\n source_h = os.path.join(d,'src','fortranobject.h')\n if newer(source_c,target_c) or newer(source_h,target_h):\n self.mkpath(os.path.dirname(target_c))\n self.copy_file(source_c,target_c)\n self.copy_file(source_h,target_h)\n else:\n assert os.path.isfile(target_c),`target_c` + ' missing'\n assert os.path.isfile(target_h),`target_h` + ' missing'\n \n for name_ext in ['-f2pywrappers.f','-f2pywrappers2.f90']:\n filename = os.path.join(target_dir,ext_name + name_ext)\n if os.path.isfile(filename):\n log.info(\" adding '%s' to sources.\" % (filename))\n f_sources.append(filename)\n\n return new_sources + f_sources\n\n def swig_sources(self, sources, extension):\n new_sources = []\n swig_sources = []\n swig_targets = {}\n target_dirs = []\n py_files = [] # swig generated .py files\n target_ext = '.c'\n typ = None\n is_cpp = 0\n skip_swig = 0\n ext_name = extension.name.split('.')[-1]\n\n for source in sources:\n (base, ext) = os.path.splitext(source)\n if ext == '.i': # SWIG interface file\n if self.inplace:\n target_dir = os.path.dirname(base)\n py_target_dir = self.ext_target_dir\n else:\n target_dir = appendpath(self.build_src, os.path.dirname(base))\n py_target_dir = target_dir\n if os.path.isfile(source):\n name = get_swig_modulename(source)\n assert name==ext_name[1:],'mismatch of extension names: '\\\n +source+' provides'\\\n ' '+`name`+' but expected '+`ext_name[1:]`\n if typ is None:\n typ = get_swig_target(source)\n is_cpp = typ=='c++'\n if is_cpp:\n target_ext = '.cpp'\n else:\n assert typ == get_swig_target(source),`typ`\n target_file = os.path.join(target_dir,'%s_wrap%s' \\\n % (name, target_ext))\n else:\n log.debug(' source %s does not exist: skipping swig\\'ing.' \\\n % (source))\n name = ext_name[1:]\n skip_swig = 1\n target_file = _find_swig_target(target_dir, name)\n if not os.path.isfile(target_file):\n log.debug(' target %s does not exist:\\n '\\\n 'Assuming %s_wrap.{c,cpp} was generated with '\\\n '\"build_src --inplace\" command.' \\\n % (target_file, name))\n target_dir = os.path.dirname(base)\n target_file = _find_swig_target(target_dir, name)\n assert os.path.isfile(target_file),`target_file`+' missing'\n log.debug(' Yes! Using %s as up-to-date target.' \\\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n py_files.append(os.path.join(py_target_dir, name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n else:\n new_sources.append(source)\n\n if not swig_sources:\n return new_sources\n\n if skip_swig:\n return new_sources + py_files\n\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n if is_cpp:\n swig_cmd.append('-c++')\n for d in extension.include_dirs:\n swig_cmd.append('-I'+d)\n for source in swig_sources:\n target = swig_targets[source]\n depends = [source] + extension.depends\n if self.force or newer_group(depends, target, 'newer'):\n log.info(\"%s: %s\" % (os.path.basename(swig) \\\n + (is_cpp and '++' or ''), source))\n self.spawn(swig_cmd + self.swigflags \\\n + [\"-o\", target, '-outdir', py_target_dir, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\n\ndef appendpath(prefix,path):\n if os.path.isabs(path):\n absprefix = os.path.abspath(prefix)\n d = os.path.commonprefix([absprefix,path])\n subpath = path[len(d):]\n assert not os.path.isabs(subpath),`subpath`\n return os.path.join(prefix,subpath)\n return os.path.join(prefix, path)\n\n#### SWIG related auxiliary functions ####\n_swig_module_name_match = re.compile(r'\\s*%module\\s*(?P[\\w_]+)',\n re.I).match\n_has_c_header = re.compile(r'-[*]-\\s*c\\s*-[*]-',re.I).search\n_has_cpp_header = re.compile(r'-[*]-\\s*c[+][+]\\s*-[*]-',re.I).search\n\ndef get_swig_target(source):\n f = open(source,'r')\n result = 'c'\n line = f.readline()\n if _has_cpp_header(line):\n result = 'c++'\n if _has_c_header(line):\n result = 'c'\n f.close()\n return result\n\ndef get_swig_modulename(source):\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _swig_module_name_match(line)\n if m:\n name = m.group('name')\n break\n f.close()\n return name\n\ndef _find_swig_target(target_dir,name):\n for ext in ['.cpp','.c']:\n target = os.path.join(target_dir,'%s_wrap%s' % (name, ext))\n if os.path.isfile(target):\n break\n return target\n\n#### F2PY related auxiliary functions ####\n\n_f2py_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',\n re.I).match\n_f2py_user_module_name_match = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?'\\\n '__user__[\\w_]*)',re.I).match\n\ndef get_f2py_modulename(source):\n name = None\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = _f2py_module_name_match(line)\n if m:\n if _f2py_user_module_name_match(line): # skip *__user__* names\n continue\n name = m.group('name')\n break\n f.close()\n return name\n\n##########################################\n", "methods": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_src.py", "nloc": 13, "complexity": 1, "token_count": 61, "parameters": [ "self" ], "start_line": 34, "end_line": 46, "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_src.py", "nloc": 25, "complexity": 7, "token_count": 179, "parameters": [ "self" ], "start_line": 48, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_src.py", "nloc": 5, "complexity": 3, "token_count": 24, "parameters": [ "self" ], "start_line": 78, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_sources", "long_name": "build_sources( self )", "filename": "build_src.py", "nloc": 7, "complexity": 3, "token_count": 41, "parameters": [ "self" ], "start_line": 84, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "build_library_sources", "long_name": "build_library_sources( self , lib_name , build_info )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "self", "lib_name", "build_info" ], "start_line": 95, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_extension_sources", "long_name": "build_extension_sources( self , ext )", "filename": "build_src.py", "nloc": 23, "complexity": 4, "token_count": 207, "parameters": [ "self", "ext" ], "start_line": 108, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "generate_sources", "long_name": "generate_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 29, "complexity": 9, "token_count": 193, "parameters": [ "self", "sources", "extension" ], "start_line": 143, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "filter_py_files", "long_name": "filter_py_files( self , sources )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "self", "sources" ], "start_line": 173, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "template_sources", "long_name": "template_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 22, "complexity": 6, "token_count": 166, "parameters": [ "self", "sources", "extension" ], "start_line": 184, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 110, "complexity": 23, "token_count": 872, "parameters": [ "self", "sources", "extension" ], "start_line": 207, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 80, "complexity": 17, "token_count": 539, "parameters": [ "self", "sources", "extension" ], "start_line": 328, "end_line": 412, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "appendpath", "long_name": "appendpath( prefix , path )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 87, "parameters": [ "prefix", "path" ], "start_line": 414, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_swig_target", "long_name": "get_swig_target( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 48, "parameters": [ "source" ], "start_line": 429, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_swig_modulename", "long_name": "get_swig_modulename( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "source" ], "start_line": 440, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "_find_swig_target", "long_name": "_find_swig_target( target_dir , name )", "filename": "build_src.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "target_dir", "name" ], "start_line": 451, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "get_f2py_modulename", "long_name": "get_f2py_modulename( source )", "filename": "build_src.py", "nloc": 13, "complexity": 4, "token_count": 65, "parameters": [ "source" ], "start_line": 465, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 } ], "methods_before": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_src.py", "nloc": 13, "complexity": 1, "token_count": 61, "parameters": [ "self" ], "start_line": 34, "end_line": 46, "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_src.py", "nloc": 25, "complexity": 7, "token_count": 179, "parameters": [ "self" ], "start_line": 48, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_src.py", "nloc": 5, "complexity": 3, "token_count": 24, "parameters": [ "self" ], "start_line": 78, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_sources", "long_name": "build_sources( self )", "filename": "build_src.py", "nloc": 7, "complexity": 3, "token_count": 41, "parameters": [ "self" ], "start_line": 84, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "build_library_sources", "long_name": "build_library_sources( self , lib_name , build_info )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 59, "parameters": [ "self", "lib_name", "build_info" ], "start_line": 95, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_extension_sources", "long_name": "build_extension_sources( self , ext )", "filename": "build_src.py", "nloc": 23, "complexity": 4, "token_count": 207, "parameters": [ "self", "ext" ], "start_line": 108, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "generate_sources", "long_name": "generate_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 29, "complexity": 9, "token_count": 193, "parameters": [ "self", "sources", "extension" ], "start_line": 143, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "filter_py_files", "long_name": "filter_py_files( self , sources )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "self", "sources" ], "start_line": 173, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "template_sources", "long_name": "template_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 22, "complexity": 6, "token_count": 166, "parameters": [ "self", "sources", "extension" ], "start_line": 184, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 107, "complexity": 22, "token_count": 822, "parameters": [ "self", "sources", "extension" ], "start_line": 207, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 117, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 80, "complexity": 17, "token_count": 539, "parameters": [ "self", "sources", "extension" ], "start_line": 325, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "appendpath", "long_name": "appendpath( prefix , path )", "filename": "build_src.py", "nloc": 8, "complexity": 2, "token_count": 87, "parameters": [ "prefix", "path" ], "start_line": 411, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_swig_target", "long_name": "get_swig_target( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 48, "parameters": [ "source" ], "start_line": 426, "end_line": 435, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_swig_modulename", "long_name": "get_swig_modulename( source )", "filename": "build_src.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "source" ], "start_line": 437, "end_line": 446, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "_find_swig_target", "long_name": "_find_swig_target( target_dir , name )", "filename": "build_src.py", "nloc": 6, "complexity": 3, "token_count": 47, "parameters": [ "target_dir", "name" ], "start_line": 448, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "get_f2py_modulename", "long_name": "get_f2py_modulename( source )", "filename": "build_src.py", "nloc": 13, "complexity": 4, "token_count": 65, "parameters": [ "source" ], "start_line": 462, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 110, "complexity": 23, "token_count": 872, "parameters": [ "self", "sources", "extension" ], "start_line": 207, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 120, "top_nesting_level": 1 } ], "nloc": 411, "complexity": 93, "token_count": 2914, "diff_parsed": { "added": [ " if type(extension) is type(()): name = extension[0]", " else: name = extension.name", " target_dir = os.path.join(*([self.build_src]\\", " +name.split('.')[:-1]))" ], "deleted": [ " target_dir = self.build_src" ] } } ] }, { "hash": "6822f58ef9231b297ff5dbd5a482621ddb22536d", "msg": "Two more setup script examples: generation of __svn_version__ and config.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-05-13T13:46:43+00:00", "author_timezone": 0, "committer_date": "2004-05-13T13:46:43+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "758a1c8fc7e08b1b62d4efc961445d57925065e7" ], "project_name": "repo_copy", "project_path": "/tmp/tmpuqr9lpll/repo_copy", "deletions": 0, "insertions": 35, "lines": 35, "files": 2, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": null, "new_path": "scipy_distutils/examples/setup_module_config.py", "filename": "setup_module_config.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,17 @@\n+#!/usr/bin/env python\n+from scipy_distutils.core import setup, Extension\n+from scipy_distutils.misc_util import default_config_dict, \\\n+ dot_join, generate_svn_version_py\n+\n+def configuration(parent_package='',parent_path=None):\n+ package_name = 'module'\n+ config = default_config_dict(package_name, parent_package)\n+\n+ ext = Extension(dot_join(config['name'],'config'),\n+ sources=[generate_config_py])\n+ config['ext_modules'].append(ext)\n+\n+ return config\n+\n+if __name__ == '__main__':\n+ setup(**configuration(parent_path=''))\n", "added_lines": 17, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\nfrom scipy_distutils.core import setup, Extension\nfrom scipy_distutils.misc_util import default_config_dict, \\\n dot_join, generate_svn_version_py\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n\n ext = Extension(dot_join(config['name'],'config'),\n sources=[generate_config_py])\n config['ext_modules'].append(ext)\n\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "source_code_before": null, "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_config.py", "nloc": 7, "complexity": 1, "token_count": 53, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_config.py", "nloc": 7, "complexity": 1, "token_count": 53, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "nloc": 12, "complexity": 1, "token_count": 88, "diff_parsed": { "added": [ "#!/usr/bin/env python", "from scipy_distutils.core import setup, Extension", "from scipy_distutils.misc_util import default_config_dict, \\", " dot_join, generate_svn_version_py", "", "def configuration(parent_package='',parent_path=None):", " package_name = 'module'", " config = default_config_dict(package_name, parent_package)", "", " ext = Extension(dot_join(config['name'],'config'),", " sources=[generate_config_py])", " config['ext_modules'].append(ext)", "", " return config", "", "if __name__ == '__main__':", " setup(**configuration(parent_path=''))" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_distutils/examples/setup_module_svn.py", "filename": "setup_module_svn.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,18 @@\n+#!/usr/bin/env python\n+from scipy_distutils.core import setup, Extension\n+from scipy_distutils.misc_util import default_config_dict, \\\n+ dot_join, generate_svn_version_py\n+\n+def configuration(parent_package='',parent_path=None):\n+ package_name = 'module'\n+ config = default_config_dict(package_name, parent_package)\n+\n+ ext = Extension(dot_join(config[\"name\"],'__svn_version__'),\n+ sources=[generate_svn_version_py])\n+ ext.local_path = local_path\n+ config['ext_modules'].append(ext)\n+\n+ return config\n+\n+if __name__ == '__main__':\n+ setup(**configuration(parent_path=''))\n", "added_lines": 18, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\nfrom scipy_distutils.core import setup, Extension\nfrom scipy_distutils.misc_util import default_config_dict, \\\n dot_join, generate_svn_version_py\n\ndef configuration(parent_package='',parent_path=None):\n package_name = 'module'\n config = default_config_dict(package_name, parent_package)\n\n ext = Extension(dot_join(config[\"name\"],'__svn_version__'),\n sources=[generate_svn_version_py])\n ext.local_path = local_path\n config['ext_modules'].append(ext)\n\n return config\n\nif __name__ == '__main__':\n setup(**configuration(parent_path=''))\n", "source_code_before": null, "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_svn.py", "nloc": 8, "complexity": 1, "token_count": 58, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' , parent_path = None )", "filename": "setup_module_svn.py", "nloc": 8, "complexity": 1, "token_count": 58, "parameters": [ "parent_package", "parent_path" ], "start_line": 6, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 } ], "nloc": 13, "complexity": 1, "token_count": 93, "diff_parsed": { "added": [ "#!/usr/bin/env python", "from scipy_distutils.core import setup, Extension", "from scipy_distutils.misc_util import default_config_dict, \\", " dot_join, generate_svn_version_py", "", "def configuration(parent_package='',parent_path=None):", " package_name = 'module'", " config = default_config_dict(package_name, parent_package)", "", " ext = Extension(dot_join(config[\"name\"],'__svn_version__'),", " sources=[generate_svn_version_py])", " ext.local_path = local_path", " config['ext_modules'].append(ext)", "", " return config", "", "if __name__ == '__main__':", " setup(**configuration(parent_path=''))" ], "deleted": [] } } ] } ]