[ { "hash": "3743e36458bcd3750e9edaba192e891633e2e1d6", "msg": "Added support to Sun WorkShop 6 F95 compiler (untested though)", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-26T18:52:12+00:00", "author_timezone": 0, "committer_date": "2004-03-26T18:52:12+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "540903640fe0f8bc6be30294f4a213f98676bfcf" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 2, "insertions": 9, "lines": 11, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/sunfcompiler.py", "new_path": "scipy_distutils/sunfcompiler.py", "filename": "sunfcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -7,11 +7,11 @@\n class SunFCompiler(FCompiler):\n \n compiler_type = 'sun'\n- version_pattern = r'(f90|f95): (Sun|Forte Developer 7) Fortran 95 (?P[^\\s]+).*'\n+ version_pattern = r'(f90|f95): (Sun|Forte Developer 7|WorkShop 6 update \\d+) Fortran 95 (?P[^\\s]+).*'\n \n executables = {\n 'version_cmd' : [\"f90\", \"-V\"],\n- 'compiler_f77' : [\"f90\", \"-f77\", \"-ftrap=%none\"],\n+ 'compiler_f77' : [\"f90\"],\n 'compiler_fix' : [\"f90\", \"-fixed\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\",\"-Bdynamic\",\"-G\"],\n@@ -22,6 +22,13 @@ class SunFCompiler(FCompiler):\n module_include_switch = '-M'\n pic_flags = ['-xcode=pic32']\n \n+ def get_flags_f77(self):\n+ ret = [\"-ftrap=%none\"]\n+ if (self.get_version() or '') >= '7':\n+ ret.append(\"-f77\")\n+ else:\n+ ret.append(\"-fixed\")\n+ return ret\n def get_opt(self):\n return ['-fast','-dalign']\n def get_arch(self):\n", "added_lines": 9, "deleted_lines": 2, "source_code": "import os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\n\nclass SunFCompiler(FCompiler):\n\n compiler_type = 'sun'\n version_pattern = r'(f90|f95): (Sun|Forte Developer 7|WorkShop 6 update \\d+) Fortran 95 (?P[^\\s]+).*'\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V\"],\n 'compiler_f77' : [\"f90\"],\n 'compiler_fix' : [\"f90\", \"-fixed\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\",\"-Bdynamic\",\"-G\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n module_dir_switch = '-moddir='\n module_include_switch = '-M'\n pic_flags = ['-xcode=pic32']\n\n def get_flags_f77(self):\n ret = [\"-ftrap=%none\"]\n if (self.get_version() or '') >= '7':\n ret.append(\"-f77\")\n else:\n ret.append(\"-fixed\")\n return ret\n def get_opt(self):\n return ['-fast','-dalign']\n def get_arch(self):\n return ['-xtarget=generic']\n def get_libraries(self):\n opt = []\n opt.extend(['fsu','sunmath','mvec','f77compat'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='sun')\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "import os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\n\nclass SunFCompiler(FCompiler):\n\n compiler_type = 'sun'\n version_pattern = r'(f90|f95): (Sun|Forte Developer 7) Fortran 95 (?P[^\\s]+).*'\n\n executables = {\n 'version_cmd' : [\"f90\", \"-V\"],\n 'compiler_f77' : [\"f90\", \"-f77\", \"-ftrap=%none\"],\n 'compiler_fix' : [\"f90\", \"-fixed\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f90\",\"-Bdynamic\",\"-G\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n module_dir_switch = '-moddir='\n module_include_switch = '-M'\n pic_flags = ['-xcode=pic32']\n\n def get_opt(self):\n return ['-fast','-dalign']\n def get_arch(self):\n return ['-xtarget=generic']\n def get_libraries(self):\n opt = []\n opt.extend(['fsu','sunmath','mvec','f77compat'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='sun')\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "sunfcompiler.py", "nloc": 7, "complexity": 3, "token_count": 39, "parameters": [ "self" ], "start_line": 25, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "sunfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 32, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_arch", "long_name": "get_arch( self )", "filename": "sunfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 34, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "sunfcompiler.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_opt", "long_name": "get_opt( self )", "filename": "sunfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 25, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_arch", "long_name": "get_arch( self )", "filename": "sunfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 27, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "sunfcompiler.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 29, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "sunfcompiler.py", "nloc": 7, "complexity": 3, "token_count": 39, "parameters": [ "self" ], "start_line": 25, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "nloc": 41, "complexity": 6, "token_count": 217, "diff_parsed": { "added": [ " version_pattern = r'(f90|f95): (Sun|Forte Developer 7|WorkShop 6 update \\d+) Fortran 95 (?P[^\\s]+).*'", " 'compiler_f77' : [\"f90\"],", " def get_flags_f77(self):", " ret = [\"-ftrap=%none\"]", " if (self.get_version() or '') >= '7':", " ret.append(\"-f77\")", " else:", " ret.append(\"-fixed\")", " return ret" ], "deleted": [ " version_pattern = r'(f90|f95): (Sun|Forte Developer 7) Fortran 95 (?P[^\\s]+).*'", " 'compiler_f77' : [\"f90\", \"-f77\", \"-ftrap=%none\"]," ] } } ] }, { "hash": "5f5c7744d8d35c362fecca2df2ce556119757362", "msg": "Reduced debugging messages", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-28T19:53:07+00:00", "author_timezone": 0, "committer_date": "2004-03-28T19:53:07+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "3743e36458bcd3750e9edaba192e891633e2e1d6" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 8, "insertions": 13, "lines": 21, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/ccompiler.py", "new_path": "scipy_distutils/ccompiler.py", "filename": "ccompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -142,10 +142,11 @@ def CCompiler_show_customization(self):\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n- print '*'*80\n- print self.__class__\n- print compiler_to_string(self)\n- print '*'*80\n+ if log._global_log.threshold<2:\n+ print '*'*80\n+ print self.__class__\n+ print compiler_to_string(self)\n+ print '*'*80\n \n CCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n@@ -177,8 +178,8 @@ def CCompiler_get_version(self, force=0, ok_status=[0]):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n- log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n- % (self.__class__))\n+ #log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n+ # % (self.__class__))\n return\n \n cmd = ' '.join(self.version_cmd)\n", "added_lines": 7, "deleted_lines": 6, "source_code": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n #log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n # % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "source_code_before": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 7, "token_count": 113, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 16, "complexity": 6, "token_count": 90, "parameters": [ "self" ], "start_line": 134, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 122, "parameters": [ "self", "force", "ok_status" ], "start_line": 175, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 214, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "methods_before": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 7, "token_count": 113, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 134, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 154, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 213, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 16, "complexity": 6, "token_count": 90, "parameters": [ "self" ], "start_line": 134, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 122, "parameters": [ "self", "force", "ok_status" ], "start_line": 175, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 } ], "nloc": 215, "complexity": 60, "token_count": 1597, "diff_parsed": { "added": [ " if log._global_log.threshold<2:", " print '*'*80", " print self.__class__", " print compiler_to_string(self)", " print '*'*80", " #log.warn('%s does not provide version_cmd and version_pattern attributes' \\", " # % (self.__class__))" ], "deleted": [ " print '*'*80", " print self.__class__", " print compiler_to_string(self)", " print '*'*80", " log.warn('%s does not provide version_cmd and version_pattern attributes' \\", " % (self.__class__))" ] } }, { "old_path": "scipy_distutils/log.py", "new_path": "scipy_distutils/log.py", "filename": "log.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -71,14 +71,18 @@ def fatal(self, msg, *args):\n def set_threshold(level):\n _global_log.threshold = level\n \n+\n+\"\"\"\n+\n def set_verbosity(v):\n- if v <= 0:\n+ if v<0:\n+ set_threshold(ERROR)\n+ elif v == 0:\n set_threshold(WARN)\n elif v == 1:\n set_threshold(INFO)\n elif v >= 2:\n set_threshold(DEBUG)\n-\"\"\"\n \n from misc_util import red_text, yellow_text, cyan_text\n _global_color_map = {\n", "added_lines": 6, "deleted_lines": 2, "source_code": "# Python 2.3 distutils.log backported to Python 2.1.x, 2.2.x\n\nimport sys\n\ndef _fix_args(args,flag=1):\n if type(args) is type(''):\n return args.replace('%','%%')\n if flag and type(args) is type(()):\n return tuple([_fix_args(a,flag=0) for a in args])\n return args\n\nif sys.version[:3]>='2.3':\n from distutils.log import *\n from distutils.log import Log as old_Log\n from distutils.log import _global_log\n class Log(old_Log):\n def _log(self, level, msg, args):\n if level>= self.threshold:\n if args:\n print _global_color_map[level](msg % _fix_args(args))\n else:\n print _global_color_map[level](msg)\n sys.stdout.flush()\n _global_log.__class__ = Log\n\nelse:\n exec \"\"\"\n# Here follows (slightly) modified copy of Python 2.3 distutils/log.py\n\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nFATAL = 5\nclass Log:\n\n def __init__(self, threshold=WARN):\n self.threshold = threshold\n\n def _log(self, level, msg, args):\n if level >= self.threshold:\n print _global_color_map[level](msg % _fix_args(args))\n sys.stdout.flush()\n\n def log(self, level, msg, *args):\n self._log(level, msg, args)\n\n def debug(self, msg, *args):\n self._log(DEBUG, msg, args)\n\n def info(self, msg, *args):\n self._log(INFO, msg, args)\n \n def warn(self, msg, *args):\n self._log(WARN, red_text(msg), args)\n \n def error(self, msg, *args):\n self._log(ERROR, msg, args)\n \n def fatal(self, msg, *args):\n self._log(FATAL, msg, args)\n\n_global_log = Log()\nlog = _global_log.log\ndebug = _global_log.debug\ninfo = _global_log.info\nwarn = _global_log.warn\nerror = _global_log.error\nfatal = _global_log.fatal\n\ndef set_threshold(level):\n _global_log.threshold = level\n\n\n\"\"\"\n\ndef set_verbosity(v):\n if v<0:\n set_threshold(ERROR)\n elif v == 0:\n set_threshold(WARN)\n elif v == 1:\n set_threshold(INFO)\n elif v >= 2:\n set_threshold(DEBUG)\n\nfrom misc_util import red_text, yellow_text, cyan_text\n_global_color_map = {\n DEBUG:cyan_text,\n INFO:yellow_text,\n WARN:red_text,\n ERROR:red_text,\n FATAL:red_text\n}\n\nset_verbosity(1)\n", "source_code_before": "# Python 2.3 distutils.log backported to Python 2.1.x, 2.2.x\n\nimport sys\n\ndef _fix_args(args,flag=1):\n if type(args) is type(''):\n return args.replace('%','%%')\n if flag and type(args) is type(()):\n return tuple([_fix_args(a,flag=0) for a in args])\n return args\n\nif sys.version[:3]>='2.3':\n from distutils.log import *\n from distutils.log import Log as old_Log\n from distutils.log import _global_log\n class Log(old_Log):\n def _log(self, level, msg, args):\n if level>= self.threshold:\n if args:\n print _global_color_map[level](msg % _fix_args(args))\n else:\n print _global_color_map[level](msg)\n sys.stdout.flush()\n _global_log.__class__ = Log\n\nelse:\n exec \"\"\"\n# Here follows (slightly) modified copy of Python 2.3 distutils/log.py\n\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nFATAL = 5\nclass Log:\n\n def __init__(self, threshold=WARN):\n self.threshold = threshold\n\n def _log(self, level, msg, args):\n if level >= self.threshold:\n print _global_color_map[level](msg % _fix_args(args))\n sys.stdout.flush()\n\n def log(self, level, msg, *args):\n self._log(level, msg, args)\n\n def debug(self, msg, *args):\n self._log(DEBUG, msg, args)\n\n def info(self, msg, *args):\n self._log(INFO, msg, args)\n \n def warn(self, msg, *args):\n self._log(WARN, red_text(msg), args)\n \n def error(self, msg, *args):\n self._log(ERROR, msg, args)\n \n def fatal(self, msg, *args):\n self._log(FATAL, msg, args)\n\n_global_log = Log()\nlog = _global_log.log\ndebug = _global_log.debug\ninfo = _global_log.info\nwarn = _global_log.warn\nerror = _global_log.error\nfatal = _global_log.fatal\n\ndef set_threshold(level):\n _global_log.threshold = level\n\ndef set_verbosity(v):\n if v <= 0:\n set_threshold(WARN)\n elif v == 1:\n set_threshold(INFO)\n elif v >= 2:\n set_threshold(DEBUG)\n\"\"\"\n\nfrom misc_util import red_text, yellow_text, cyan_text\n_global_color_map = {\n DEBUG:cyan_text,\n INFO:yellow_text,\n WARN:red_text,\n ERROR:red_text,\n FATAL:red_text\n}\n\nset_verbosity(1)\n", "methods": [ { "name": "_fix_args", "long_name": "_fix_args( args , flag = 1 )", "filename": "log.py", "nloc": 6, "complexity": 5, "token_count": 63, "parameters": [ "args", "flag" ], "start_line": 5, "end_line": 10, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_log", "long_name": "_log( self , level , msg , args )", "filename": "log.py", "nloc": 7, "complexity": 3, "token_count": 51, "parameters": [ "self", "level", "msg", "args" ], "start_line": 17, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 }, { "name": "set_verbosity", "long_name": "set_verbosity( v )", "filename": "log.py", "nloc": 9, "complexity": 5, "token_count": 41, "parameters": [ "v" ], "start_line": 77, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_fix_args", "long_name": "_fix_args( args , flag = 1 )", "filename": "log.py", "nloc": 6, "complexity": 5, "token_count": 63, "parameters": [ "args", "flag" ], "start_line": 5, "end_line": 10, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_log", "long_name": "_log( self , level , msg , args )", "filename": "log.py", "nloc": 7, "complexity": 3, "token_count": 51, "parameters": [ "self", "level", "msg", "args" ], "start_line": 17, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 } ], "changed_methods": [ { "name": "set_verbosity", "long_name": "set_verbosity( v )", "filename": "log.py", "nloc": 9, "complexity": 5, "token_count": 41, "parameters": [ "v" ], "start_line": 77, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "nloc": 88, "complexity": 13, "token_count": 241, "diff_parsed": { "added": [ "", "\"\"\"", "", " if v<0:", " set_threshold(ERROR)", " elif v == 0:" ], "deleted": [ " if v <= 0:", "\"\"\"" ] } } ] }, { "hash": "406a04b80cbdfdc457a1723a64c8cc5a8050aaa7", "msg": "Introduced reldir argument to set_local_path.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-28T19:54:30+00:00", "author_timezone": 0, "committer_date": "2004-03-28T19:54:30+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5f5c7744d8d35c362fecca2df2ce556119757362" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 2, "insertions": 2, "lines": 4, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -52,7 +52,7 @@ def set_package_path(level=1):\n sys.path.insert(0,d1)\n \n __all__.append('set_local_path')\n-def set_local_path(level=1):\n+def set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n \n The caller is responsible for removing this path by using\n@@ -65,7 +65,7 @@ def set_local_path(level=1):\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n- local_path = os.path.dirname(os.path.abspath(testfile))\n+ local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n", "source_code_before": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\n \ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files\n\ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n\n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files\n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n\n return good_files\n\n__all__.append('harvest_modules')\ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n\n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n\n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f)\n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception()\n\n return all_modules\n\n__all__.append('harvest_packages')\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n\n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files:\n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception()\n return all_packages\n\n__all__.append('harvest_modules_and_packages')\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\n__all__.append('harvest_test_suites')\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object\n (not a string)\n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite)\n else:\n print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\n except:\n print ' !! FAILURE building test for ', module.__name__\n print ' ',\n output_exception()\n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has\n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[1:]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception()\n\n\n# Utility function to facilitate testing.\n\n__all__.append('assert_equal')\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits\n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\n msg = '\\nArrays are not almost equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n", "methods": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 149, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 164, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 198, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 204, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 227, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 269, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 291, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 304, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 331, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 357, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 365, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 387, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 426, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 463, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 472, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 510, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 540, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 572, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 589, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 606, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 658, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 661, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 686, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 708, "end_line": 717, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 719, "end_line": 729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 149, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 164, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 198, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 204, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 227, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 269, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 291, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 304, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 331, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 357, "end_line": 363, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 365, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 387, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 426, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 463, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 472, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 510, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 540, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 572, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 589, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 606, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 658, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 661, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 686, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 708, "end_line": 717, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 719, "end_line": 729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "set_local_path", "long_name": "set_local_path( reldir = '' , level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 97, "parameters": [ "reldir", "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 } ], "nloc": 527, "complexity": 134, "token_count": 3935, "diff_parsed": { "added": [ "def set_local_path(reldir='', level=1):", " local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)" ], "deleted": [ "def set_local_path(level=1):", " local_path = os.path.dirname(os.path.abspath(testfile))" ] } } ] }, { "hash": "b51513377fd4619784f1fa1748037bb7318c81a1", "msg": "Fixed exec_command for commands with spaces", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-29T15:52:29+00:00", "author_timezone": 0, "committer_date": "2004-03-29T15:52:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "406a04b80cbdfdc457a1723a64c8cc5a8050aaa7" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 8, "insertions": 8, "lines": 16, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -144,10 +144,11 @@ def find_executable(exe, path=None):\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n- f_ext = fn+s\n+ f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n+ exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n@@ -364,10 +365,11 @@ def _exec_command( command, use_shell=None, **env ):\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n- if os.name in ['nt','dos']:\n- # argv[0] might be internal command\n- argv = [os.environ['COMSPEC'],'/C']+argv\n- using_command = 1\n+ argv[0] = quote_arg(argv[0])\n+ if os.name in ['nt','dos']:\n+ # argv[0] might be internal command\n+ argv = [os.environ['COMSPEC'],'/C']+argv\n+ using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n@@ -394,10 +396,8 @@ def _exec_command( command, use_shell=None, **env ):\n else:\n os.dup2(fout.fileno(),se_fileno)\n \n- argv0 = quote_arg(argv[0])\n-\n try:\n- status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n+ status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n", "added_lines": 8, "deleted_lines": 8, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = quote_arg(argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 165, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 243, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 294, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 555, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 549, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 555, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 } ], "nloc": 421, "complexity": 134, "token_count": 3332, "diff_parsed": { "added": [ " f_ext = os.path.realpath(fn+s)", " exe = os.path.realpath(exe)", " argv[0] = quote_arg(argv[0])", " if os.name in ['nt','dos']:", " # argv[0] might be internal command", " argv = [os.environ['COMSPEC'],'/C']+argv", " using_command = 1", " status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)" ], "deleted": [ " f_ext = fn+s", " if os.name in ['nt','dos']:", " # argv[0] might be internal command", " argv = [os.environ['COMSPEC'],'/C']+argv", " using_command = 1", " argv0 = quote_arg(argv[0])", "", " status = spawn_command(os.P_WAIT,argv0,argv,os.environ)" ] } } ] }, { "hash": "766c97f887162de06ca60caedbb28252499e464d", "msg": "Added test for f2py --include_paths option", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-29T16:57:23+00:00", "author_timezone": 0, "committer_date": "2004-03-29T16:57:23+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "b51513377fd4619784f1fa1748037bb7318c81a1" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 7, "insertions": 12, "lines": 19, "files": 4, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/fcompiler.py", "new_path": "scipy_distutils/fcompiler.py", "filename": "fcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -786,7 +786,7 @@ def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n is_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n _has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n _has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n-_free_f90_start = re.compile(r'[^c*][^\\s\\d\\t]',re.I).match\n+_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match\n def is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"scipy_distutils.fcompiler\n\nContains FCompiler, an abstract base class that defines the interface\nfor the Scipy_distutils Fortran compiler abstraction model.\n\n\"\"\"\n\nimport re\nimport os\nimport sys\nimport atexit\nfrom types import StringType, NoneType, ListType, TupleType\nfrom glob import glob\n\nfrom distutils.version import StrictVersion\nfrom scipy_distutils.ccompiler import CCompiler, gen_lib_options\n# distutils.ccompiler provides the following functions:\n# gen_preprocess_options(macros, include_dirs)\n# gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)\nfrom distutils.errors import DistutilsModuleError,DistutilsArgError,\\\n DistutilsExecError,CompileError,LinkError,DistutilsPlatformError\nfrom distutils.core import Command\nfrom distutils.util import split_quoted\nfrom distutils.fancy_getopt import FancyGetopt\nfrom distutils.sysconfig import get_config_var\nfrom distutils.spawn import _nt_quote_args \n\n\nfrom scipy_distutils.command.config_compiler import config_fc\n\nimport log\nfrom misc_util import compiler_to_string\nfrom exec_command import find_executable, exec_command\n\nclass FCompiler(CCompiler):\n \"\"\" Abstract base class to define the interface that must be implemented\n by real Fortran compiler classes.\n\n Methods that subclasses may redefine:\n\n get_version_cmd(), get_linker_so(), get_version()\n get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()\n get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),\n get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),\n get_flags_arch_f90(), get_flags_debug_f90(),\n get_flags_fix(), get_flags_linker_so(), get_flags_version()\n\n DON'T call these methods (except get_version) after\n constructing a compiler instance or inside any other method.\n All methods, except get_version_cmd() and get_flags_version(), may\n call get_version() method.\n\n After constructing a compiler instance, always call customize(dist=None)\n method that finalizes compiler construction and makes the following\n attributes available:\n compiler_f77\n compiler_f90\n compiler_fix\n linker_so\n archiver\n ranlib\n libraries\n library_dirs\n \"\"\"\n # CCompiler defines the following attributes:\n # compiler_type\n # src_extensions\n # obj_extension\n # static_lib_extension\n # shared_lib_extension\n # static_lib_format\n # shared_lib_format\n # exe_extension\n # language_map ### REDEFINED\n # language_order ### REDEFINED\n # and the following public methods:\n # set_executables(**args)\n # set_executable(key,value)\n # define_macro(name, value=None)\n # undefine_macro(name)\n # add_include_dir(dir)\n # set_include_dirs(dirs)\n # add_library(libname)\n # set_libraries(libnames)\n # add_library_dir(dir)\n # set_library_dirs(dirs)\n # add_runtime_library_dir(dir)\n # set_runtime_library_dirs(dirs)\n # add_link_object(object)\n # set_link_objects(objects)\n #\n # detect_language(sources) ### USABLE\n #\n # preprocess(source,output_file=None,macros=None,include_dirs=None,\n # extra_preargs=None,extra_postargs=None)\n # compile(sources, output_dir=None, macros=None,\n # include_dirs=None, debug=0, extra_preargs=None,\n # extra_postargs=None, depends=None)\n # create_static_lib(objects,output_libname,output_dir=None,debug=0,target_lang=None):\n # link(target_desc, objects, output_filename, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None,\n # build_temp=None, target_lang=None)\n # link_shared_lib(objects, output_libname, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None,\n # extra_postargs=None, build_temp=None, target_lang=None)\n # link_shared_object(objects,output_filename,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # export_symbols=None,debug=0,extra_preargs=None,\n # extra_postargs=None,build_temp=None,target_lang=None)\n # link_executable(objects,output_progname,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # debug=0,extra_preargs=None,extra_postargs=None,target_lang=None)\n #\n # library_dir_option(dir)\n # runtime_library_dir_option(dir)\n # library_option(lib)\n # has_function(funcname,includes=None,include_dirs=None,\n # libraries=None,library_dirs=None)\n # find_library_file(dirs, lib, debug=0)\n #\n # object_filenames(source_filenames, strip_dir=0, output_dir='')\n # shared_object_filename(basename, strip_dir=0, output_dir='')\n # executable_filenamee(basename, strip_dir=0, output_dir='')\n # library_filename(libname, lib_type='static',strip_dir=0, output_dir=''):\n #\n # announce(msg, level=1)\n # debug_print(msg)\n # warn(msg)\n # execute(func, args, msg=None, level=1)\n # spawn(cmd)\n # move_file(src,dst)\n # mkpath(name, mode=0777)\n #\n\n language_map = {'.f':'f77',\n '.for':'f77',\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n '.f95':'f90'}\n language_order = ['f90','f77']\n\n version_pattern = None\n\n executables = {\n 'version_cmd' : [\"f77\",\"-v\"],\n 'compiler_f77' : [\"f77\"],\n 'compiler_f90' : [\"f90\"],\n 'compiler_fix' : [\"f90\",\"-fixed\"],\n 'linker_so' : [\"f90\",\"-shared\"],\n #'linker_exe' : [\"f90\"], # XXX do we need it??\n 'archiver' : [\"ar\",\"-cr\"],\n 'ranlib' : None,\n }\n\n compile_switch = \"-c\"\n object_switch = \"-o \" # Ending space matters! It will be stripped\n # but if it is missing then object_switch\n # will be prefixed to object file name by\n # string concatenation.\n library_switch = \"-o \" # Ditto!\n\n # Switch to specify where module files are created and searched\n # for USE statement. Normally it is a string and also here ending\n # space matters. See above.\n module_dir_switch = None\n\n # Switch to specify where module files are searched for USE statement.\n module_include_switch = '-I' \n\n pic_flags = [] # Flags to create position-independent code\n\n src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n static_lib_format = \"lib%s%s\" # or %s%s\n shared_lib_format = \"%s%s\"\n exe_extension = \"\"\n\n ######################################################################\n ## Methods that subclasses may redefine. But don't call these methods!\n ## They are private to FCompiler class and may return unexpected\n ## results if used elsewhere. So, you have been warned..\n\n def get_version_cmd(self):\n \"\"\" Compiler command to print out version information. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n cmd = self.executables['version_cmd']\n if cmd is not None:\n cmd = cmd[0]\n if cmd==f77:\n cmd = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if cmd==f90:\n cmd = self.compiler_f90[0]\n return cmd\n\n def get_linker_so(self):\n \"\"\" Linker command to build shared libraries. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n ln = self.executables['linker_so']\n if ln is not None:\n ln = ln[0]\n if ln==f77:\n ln = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if ln==f90:\n ln = self.compiler_f90[0]\n return ln\n\n def get_flags(self):\n \"\"\" List of flags common to all compiler types. \"\"\"\n return [] + self.pic_flags\n def get_flags_version(self):\n \"\"\" List of compiler flags to print out version information. \"\"\"\n if self.executables['version_cmd']:\n return self.executables['version_cmd'][1:]\n return []\n def get_flags_f77(self):\n \"\"\" List of Fortran 77 specific flags. \"\"\"\n if self.executables['compiler_f77']:\n return self.executables['compiler_f77'][1:]\n return []\n def get_flags_f90(self):\n \"\"\" List of Fortran 90 specific flags. \"\"\"\n if self.executables['compiler_f90']:\n return self.executables['compiler_f90'][1:]\n return []\n def get_flags_fix(self):\n \"\"\" List of Fortran 90 fixed format specific flags. \"\"\"\n if self.executables['compiler_fix']:\n return self.executables['compiler_fix'][1:]\n return []\n def get_flags_linker_so(self):\n \"\"\" List of linker flags to build a shared library. \"\"\"\n if self.executables['linker_so']:\n return self.executables['linker_so'][1:]\n return []\n def get_flags_ar(self):\n \"\"\" List of archiver flags. \"\"\"\n if self.executables['archiver']:\n return self.executables['archiver'][1:]\n return []\n def get_flags_opt(self):\n \"\"\" List of architecture independent compiler flags. \"\"\"\n return []\n def get_flags_arch(self):\n \"\"\" List of architecture dependent compiler flags. \"\"\"\n return []\n def get_flags_debug(self):\n \"\"\" List of compiler flags to compile with debugging information. \"\"\"\n return []\n get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt\n get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch\n get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug\n\n def get_libraries(self):\n \"\"\" List of compiler libraries. \"\"\"\n return self.libraries[:]\n def get_library_dirs(self):\n \"\"\" List of compiler library directories. \"\"\"\n return self.library_dirs[:]\n\n ############################################################\n\n ## Public methods:\n\n def customize(self, dist=None):\n \"\"\" Customize Fortran compiler.\n\n This method gets Fortran compiler specific information from\n (i) class definition, (ii) environment, (iii) distutils config\n files, and (iv) command line.\n\n This method should be always called after constructing a\n compiler instance. But not in __init__ because Distribution\n instance is needed for (iii) and (iv).\n \"\"\"\n log.info('customize %s' % (self.__class__.__name__))\n if dist is None:\n # These hooks are for testing only!\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n conf = dist.get_option_dict('config_fc')\n\n noopt = conf.get('noopt',[None,0])[1]\n noarch = conf.get('noarch',[None,noopt])[1]\n debug = conf.get('debug',[None,0])[1]\n\n f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))\n f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))\n # Temporarily setting f77,f90 compilers so that\n # version_cmd can use their executables.\n if f77:\n self.set_executables(compiler_f77=[f77])\n if f90:\n self.set_executables(compiler_f90=[f90])\n\n # Must set version_cmd before others as self.get_flags*\n # methods may call self.get_version.\n vers_cmd = self.__get_cmd(self.get_version_cmd)\n if vers_cmd:\n vflags = self.__get_flags(self.get_flags_version)\n self.set_executables(version_cmd=[vers_cmd]+vflags)\n\n if f77:\n f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',\n (conf,'f77flags'))\n if f90:\n f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',\n (conf,'f90flags'))\n\n # XXX Assuming that free format is default for f90 compiler.\n fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))\n if fix:\n fixflags = self.__get_flags(self.get_flags_fix) + f90flags\n\n oflags,aflags,dflags = [],[],[]\n if not noopt:\n oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))\n if f77 and self.get_flags_opt is not self.get_flags_opt_f77:\n f77flags += self.__get_flags(self.get_flags_opt_f77)\n if f90 and self.get_flags_opt is not self.get_flags_opt_f90:\n f90flags += self.__get_flags(self.get_flags_opt_f90)\n if fix and self.get_flags_opt is not self.get_flags_opt_f90:\n fixflags += self.__get_flags(self.get_flags_opt_f90)\n if not noarch:\n aflags = self.__get_flags(self.get_flags_arch,'FARCH',\n (conf,'arch'))\n if f77 and self.get_flags_arch is not self.get_flags_arch_f77:\n f77flags += self.__get_flags(self.get_flags_arch_f77)\n if f90 and self.get_flags_arch is not self.get_flags_arch_f90:\n f90flags += self.__get_flags(self.get_flags_arch_f90)\n if fix and self.get_flags_arch is not self.get_flags_arch_f90:\n fixflags += self.__get_flags(self.get_flags_arch_f90)\n if debug:\n dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')\n if f77 and self.get_flags_debug is not self.get_flags_debug_f77:\n f77flags += self.__get_flags(self.get_flags_debug_f77)\n if f90 and self.get_flags_debug is not self.get_flags_debug_f90:\n f90flags += self.__get_flags(self.get_flags_debug_f90)\n if fix and self.get_flags_debug is not self.get_flags_debug_f90:\n fixflags += self.__get_flags(self.get_flags_debug_f90)\n\n fflags = self.__get_flags(self.get_flags,'FFLAGS') \\\n + dflags + oflags + aflags\n\n if f77:\n self.set_executables(compiler_f77=[f77]+f77flags+fflags)\n if f90:\n self.set_executables(compiler_f90=[f90]+f90flags+fflags)\n if fix:\n self.set_executables(compiler_fix=[fix]+fixflags+fflags)\n\n #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS\n linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')\n if linker_so:\n linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')\n self.set_executables(linker_so=[linker_so]+linker_so_flags)\n\n ar = self.__get_cmd('archiver','AR')\n if ar:\n arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')\n self.set_executables(archiver=[ar]+arflags)\n\n ranlib = self.__get_cmd('ranlib','RANLIB')\n if ranlib:\n self.set_executables(ranlib=[ranlib])\n\n self.set_library_dirs(self.get_library_dirs())\n self.set_libraries(self.get_libraries())\n\n verbose = conf.get('verbose',[None,0])[1]\n if verbose:\n self.dump_properties()\n return\n\n def dump_properties(self):\n \"\"\" Print out the attributes of a compiler instance. \"\"\"\n props = []\n for key in self.executables.keys() + \\\n ['version','libraries','library_dirs',\n 'object_switch','compile_switch']:\n if hasattr(self,key):\n v = getattr(self,key)\n props.append((key, None, '= '+`v`))\n props.sort()\n\n pretty_printer = FancyGetopt(props)\n for l in pretty_printer.generate_help(\"%s instance properties:\" \\\n % (self.__class__.__name__)):\n if l[:4]==' --':\n l = ' ' + l[4:]\n print l\n return\n\n ###################\n\n def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):\n \"\"\"Compile 'src' to product 'obj'.\"\"\"\n if is_f_file(src):\n flavor = ':f77'\n compiler = self.compiler_f77\n elif is_free_format(src):\n flavor = ':f90'\n compiler = self.compiler_f90\n if compiler is None:\n raise DistutilsExecError, 'f90 not supported by '\\\n +self.__class__.__name__\n else:\n flavor = ':fix'\n compiler = self.compiler_fix\n if compiler is None:\n raise DistutilsExecError, 'f90 (fixed) not supported by '\\\n +self.__class__.__name__\n if self.object_switch[-1]==' ':\n o_args = [self.object_switch.strip(),obj]\n else:\n o_args = [self.object_switch.strip()+obj]\n\n assert self.compile_switch.strip()\n s_args = [self.compile_switch, src]\n\n if os.name == 'nt':\n compiler = _nt_quote_args(compiler)\n command = compiler + cc_args + s_args + o_args + extra_postargs\n\n display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,\n src)\n try:\n self.spawn(command,display=display)\n except DistutilsExecError, msg:\n raise CompileError, msg\n\n return\n\n def module_options(self, module_dirs, module_build_dir):\n options = []\n if self.module_dir_switch is not None:\n if self.module_dir_switch[-1]==' ':\n options.extend([self.module_dir_switch.strip(),module_build_dir])\n else:\n options.append(self.module_dir_switch.strip()+module_build_dir)\n else:\n print 'XXX: module_build_dir=%r option ignored' % (module_build_dir)\n print 'XXX: Fix module_dir_switch for ',self.__class__.__name__\n if self.module_include_switch is not None:\n for d in [module_build_dir]+module_dirs:\n options.append('%s%s' % (self.module_include_switch, d))\n else:\n print 'XXX: module_dirs=%r option ignored' % (module_dirs)\n print 'XXX: Fix module_include_switch for ',self.__class__.__name__\n return options\n\n def library_option(self, lib):\n return \"-l\" + lib\n def library_dir_option(self, dir):\n return \"-L\" + dir\n\n# def _get_cc_args(self, pp_opts, debug, extra_preargs):\n# return []\n\n if sys.version[:3]<'2.3':\n def compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if output_dir is None: output_dir = self.output_dir\n if macros is None: macros = self.macros\n elif type(macros) is ListType: macros = macros + (self.macros or [])\n if include_dirs is None: include_dirs = self.include_dirs\n elif type(include_dirs) in (ListType, TupleType):\n include_dirs = list(include_dirs) + (self.include_dirs or [])\n if extra_preargs is None: extra_preargs=[]\n from distutils.sysconfig import python_build\n objects = self.object_filenames(sources,strip_dir=python_build,\n output_dir=output_dir)\n from distutils.ccompiler import gen_preprocess_options\n pp_opts = gen_preprocess_options(macros, include_dirs)\n build = {}\n for i in range(len(sources)):\n src,obj = sources[i],objects[i]\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n def detect_language(self, sources):\n return\n\n def link(self, target_desc, objects,\n output_filename, output_dir=None, libraries=None,\n library_dirs=None, runtime_library_dirs=None,\n export_symbols=None, debug=0, extra_preargs=None,\n extra_postargs=None, build_temp=None, target_lang=None):\n objects, output_dir = self._fix_object_args(objects, output_dir)\n libraries, library_dirs, runtime_library_dirs = \\\n self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)\n\n lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,\n libraries)\n if type(output_dir) not in (StringType, NoneType):\n raise TypeError, \"'output_dir' must be a string or None\"\n if output_dir is not None:\n output_filename = os.path.join(output_dir, output_filename)\n\n if self._need_link(objects, output_filename):\n if self.library_switch[-1]==' ':\n o_args = [self.library_switch.strip(),output_filename]\n else:\n o_args = [self.library_switch.strip()+output_filename]\n ld_args = (objects + self.objects +\n lib_opts + o_args)\n if debug:\n ld_args[:0] = ['-g']\n if extra_preargs:\n ld_args[:0] = extra_preargs\n if extra_postargs:\n ld_args.extend(extra_postargs)\n self.mkpath(os.path.dirname(output_filename))\n if target_desc == CCompiler.EXECUTABLE:\n raise NotImplementedError,self.__class__.__name__+'.linker_exe attribute'\n else:\n linker = self.linker_so[:]\n if os.name == 'nt':\n linker = _nt_quote_args(linker)\n command = linker + ld_args\n try:\n self.spawn(command)\n except DistutilsExecError, msg:\n raise LinkError, msg\n else:\n log.debug(\"skipping %s (up-to-date)\", output_filename)\n return\n\n ############################################################\n\n ## Private methods:\n\n def __get_cmd(self, command, envvar=None, confvar=None):\n if command is None:\n var = None\n elif type(command) is type(''):\n var = self.executables[command]\n if var is not None:\n var = var[0]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n return var\n\n def __get_flags(self, command, envvar=None, confvar=None):\n if command is None:\n var = []\n elif type(command) is type(''):\n var = self.executables[command][1:]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n if type(var) is type(''):\n var = split_quoted(var)\n return var\n\n ## class FCompiler\n\n##############################################################################\n\nfcompiler_class = {'gnu':('gnufcompiler','GnuFCompiler',\n \"GNU Fortran Compiler\"),\n 'pg':('pgfcompiler','PGroupFCompiler',\n \"Portland Group Fortran Compiler\"),\n 'absoft':('absoftfcompiler','AbsoftFCompiler',\n \"Absoft Corp Fortran Compiler\"),\n 'mips':('mipsfcompiler','MipsFCompiler',\n \"MIPSpro Fortran Compiler\"),\n 'sun':('sunfcompiler','SunFCompiler',\n \"Sun|Forte Fortran 95 Compiler\"),\n 'intel':('intelfcompiler','IntelFCompiler',\n \"Intel Fortran Compiler for 32-bit apps\"),\n 'intelv':('intelfcompiler','IntelVisualFCompiler',\n \"Intel Visual Fortran Compiler for 32-bit apps\"),\n 'intele':('intelfcompiler','IntelItaniumFCompiler',\n \"Intel Fortran Compiler for Itanium apps\"),\n 'intelev':('intelfcompiler','IntelItaniumVisualFCompiler',\n \"Intel Visual Fortran Compiler for Itanium apps\"),\n 'nag':('nagfcompiler','NAGFCompiler',\n \"NAGWare Fortran 95 Compiler\"),\n 'compaq':('compaqfcompiler','CompaqFCompiler',\n \"Compaq Fortran Compiler\"),\n 'compaqv':('compaqfcompiler','CompaqVisualFCompiler',\n \"DIGITAL|Compaq Visual Fortran Compiler\"),\n 'vast':('vastfcompiler','VastFCompiler',\n \"Pacific-Sierra Research Fortran 90 Compiler\"),\n 'hpux':('hpuxfcompiler','HPUXFCompiler',\n \"HP Fortran 90 Compiler\"),\n 'lahey':('laheyfcompiler','LaheyFCompiler',\n \"Lahey/Fujitsu Fortran 95 Compiler\"),\n 'ibm':('ibmfcompiler','IbmFCompiler',\n \"IBM XL Fortran Compiler\"),\n 'f':('fcompiler','FFCompiler',\n \"Fortran Company/NAG F Compiler\"),\n }\n\n_default_compilers = (\n # Platform mappings\n ('win32',('gnu','intelv','absoft','compaqv','intelev')),\n ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev')),\n ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',\n 'intele')),\n ('darwin.*',('nag','absoft','ibm','gnu')),\n ('sunos.*',('forte','gnu','sun')),\n ('irix.*',('mips','gnu')),\n ('aix.*',('ibm','gnu')),\n # OS mappings\n ('posix',('gnu',)),\n ('nt',('gnu',)),\n ('mac',('gnu',)),\n )\n\ndef _find_existing_fcompiler(compilers, osname=None, platform=None):\n for compiler in compilers:\n v = None\n try:\n c = new_fcompiler(plat=platform, compiler=compiler)\n c.customize()\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is not None:\n return compiler\n return\n\ndef get_default_fcompiler(osname=None, platform=None):\n \"\"\" Determine the default Fortran compiler to use for the given platform. \"\"\"\n if osname is None:\n osname = os.name\n if platform is None:\n platform = sys.platform\n matching_compilers = []\n for pattern, compiler in _default_compilers:\n if re.match(pattern, platform) is not None or \\\n re.match(pattern, osname) is not None:\n if type(compiler) is type(()):\n matching_compilers.extend(list(compiler))\n else:\n matching_compilers.append(compiler)\n if not matching_compilers:\n matching_compilers.append('gnu')\n compiler = _find_existing_fcompiler(matching_compilers,\n osname=osname,\n platform=platform)\n if compiler is not None:\n return compiler\n return matching_compilers[0]\n\ndef new_fcompiler(plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n \"\"\" Generate an instance of some FCompiler subclass for the supplied\n platform/compiler combination.\n \"\"\"\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_fcompiler(plat)\n (module_name, class_name, long_description) = fcompiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile Fortran code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler.\" % compiler\n msg = msg + \" Supported compilers are: %s)\" \\\n % (','.join(fcompiler_class.keys()))\n raise DistutilsPlatformError, msg\n\n try:\n module_name = 'scipy_distutils.'+module_name\n __import__ (module_name)\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile Fortran code: unable to load module '%s'\" % \\\n module_name\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile Fortran code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\ndef show_fcompilers(dist = None):\n \"\"\" Print list of available compilers (used by the \"--help-fcompiler\"\n option to \"config_fc\").\n \"\"\"\n if dist is None:\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n compilers = []\n compilers_na = []\n compilers_ni = []\n for compiler in fcompiler_class.keys():\n v = 'N/A'\n try:\n c = new_fcompiler(compiler=compiler)\n c.customize(dist)\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is None:\n compilers_na.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n elif v=='N/A':\n compilers_ni.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n else:\n compilers.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2] + ' (%s)' % v))\n compilers.sort()\n compilers_na.sort()\n pretty_printer = FancyGetopt(compilers)\n pretty_printer.print_help(\"List of available Fortran compilers:\")\n pretty_printer = FancyGetopt(compilers_na)\n pretty_printer.print_help(\"List of unavailable Fortran compilers:\")\n if compilers_ni:\n pretty_printer = FancyGetopt(compilers_ni)\n pretty_printer.print_help(\"List of unimplemented Fortran compilers:\")\n print \"For compiler details, run 'config_fc --verbose' setup command.\"\n\ndef dummy_fortran_file():\n import tempfile\n dummy_name = tempfile.mktemp()+'__dummy'\n dummy = open(dummy_name+'.f','w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n save_th = log._global_log.threshold\n log.set_threshold(log_threshold)\n try: os.remove(name+'.f'); log.debug('removed '+name+'.f')\n except OSError: pass\n try: os.remove(name+'.o'); log.debug('removed '+name+'.o')\n except OSError: pass\n log.set_threshold(save_th)\n atexit.register(rm_file)\n return dummy_name\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\nif __name__ == '__main__':\n show_fcompilers()\n", "source_code_before": "\"\"\"scipy_distutils.fcompiler\n\nContains FCompiler, an abstract base class that defines the interface\nfor the Scipy_distutils Fortran compiler abstraction model.\n\n\"\"\"\n\nimport re\nimport os\nimport sys\nimport atexit\nfrom types import StringType, NoneType, ListType, TupleType\nfrom glob import glob\n\nfrom distutils.version import StrictVersion\nfrom scipy_distutils.ccompiler import CCompiler, gen_lib_options\n# distutils.ccompiler provides the following functions:\n# gen_preprocess_options(macros, include_dirs)\n# gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)\nfrom distutils.errors import DistutilsModuleError,DistutilsArgError,\\\n DistutilsExecError,CompileError,LinkError,DistutilsPlatformError\nfrom distutils.core import Command\nfrom distutils.util import split_quoted\nfrom distutils.fancy_getopt import FancyGetopt\nfrom distutils.sysconfig import get_config_var\nfrom distutils.spawn import _nt_quote_args \n\n\nfrom scipy_distutils.command.config_compiler import config_fc\n\nimport log\nfrom misc_util import compiler_to_string\nfrom exec_command import find_executable, exec_command\n\nclass FCompiler(CCompiler):\n \"\"\" Abstract base class to define the interface that must be implemented\n by real Fortran compiler classes.\n\n Methods that subclasses may redefine:\n\n get_version_cmd(), get_linker_so(), get_version()\n get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()\n get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),\n get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),\n get_flags_arch_f90(), get_flags_debug_f90(),\n get_flags_fix(), get_flags_linker_so(), get_flags_version()\n\n DON'T call these methods (except get_version) after\n constructing a compiler instance or inside any other method.\n All methods, except get_version_cmd() and get_flags_version(), may\n call get_version() method.\n\n After constructing a compiler instance, always call customize(dist=None)\n method that finalizes compiler construction and makes the following\n attributes available:\n compiler_f77\n compiler_f90\n compiler_fix\n linker_so\n archiver\n ranlib\n libraries\n library_dirs\n \"\"\"\n # CCompiler defines the following attributes:\n # compiler_type\n # src_extensions\n # obj_extension\n # static_lib_extension\n # shared_lib_extension\n # static_lib_format\n # shared_lib_format\n # exe_extension\n # language_map ### REDEFINED\n # language_order ### REDEFINED\n # and the following public methods:\n # set_executables(**args)\n # set_executable(key,value)\n # define_macro(name, value=None)\n # undefine_macro(name)\n # add_include_dir(dir)\n # set_include_dirs(dirs)\n # add_library(libname)\n # set_libraries(libnames)\n # add_library_dir(dir)\n # set_library_dirs(dirs)\n # add_runtime_library_dir(dir)\n # set_runtime_library_dirs(dirs)\n # add_link_object(object)\n # set_link_objects(objects)\n #\n # detect_language(sources) ### USABLE\n #\n # preprocess(source,output_file=None,macros=None,include_dirs=None,\n # extra_preargs=None,extra_postargs=None)\n # compile(sources, output_dir=None, macros=None,\n # include_dirs=None, debug=0, extra_preargs=None,\n # extra_postargs=None, depends=None)\n # create_static_lib(objects,output_libname,output_dir=None,debug=0,target_lang=None):\n # link(target_desc, objects, output_filename, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None,\n # build_temp=None, target_lang=None)\n # link_shared_lib(objects, output_libname, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None,\n # extra_postargs=None, build_temp=None, target_lang=None)\n # link_shared_object(objects,output_filename,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # export_symbols=None,debug=0,extra_preargs=None,\n # extra_postargs=None,build_temp=None,target_lang=None)\n # link_executable(objects,output_progname,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # debug=0,extra_preargs=None,extra_postargs=None,target_lang=None)\n #\n # library_dir_option(dir)\n # runtime_library_dir_option(dir)\n # library_option(lib)\n # has_function(funcname,includes=None,include_dirs=None,\n # libraries=None,library_dirs=None)\n # find_library_file(dirs, lib, debug=0)\n #\n # object_filenames(source_filenames, strip_dir=0, output_dir='')\n # shared_object_filename(basename, strip_dir=0, output_dir='')\n # executable_filenamee(basename, strip_dir=0, output_dir='')\n # library_filename(libname, lib_type='static',strip_dir=0, output_dir=''):\n #\n # announce(msg, level=1)\n # debug_print(msg)\n # warn(msg)\n # execute(func, args, msg=None, level=1)\n # spawn(cmd)\n # move_file(src,dst)\n # mkpath(name, mode=0777)\n #\n\n language_map = {'.f':'f77',\n '.for':'f77',\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n '.f95':'f90'}\n language_order = ['f90','f77']\n\n version_pattern = None\n\n executables = {\n 'version_cmd' : [\"f77\",\"-v\"],\n 'compiler_f77' : [\"f77\"],\n 'compiler_f90' : [\"f90\"],\n 'compiler_fix' : [\"f90\",\"-fixed\"],\n 'linker_so' : [\"f90\",\"-shared\"],\n #'linker_exe' : [\"f90\"], # XXX do we need it??\n 'archiver' : [\"ar\",\"-cr\"],\n 'ranlib' : None,\n }\n\n compile_switch = \"-c\"\n object_switch = \"-o \" # Ending space matters! It will be stripped\n # but if it is missing then object_switch\n # will be prefixed to object file name by\n # string concatenation.\n library_switch = \"-o \" # Ditto!\n\n # Switch to specify where module files are created and searched\n # for USE statement. Normally it is a string and also here ending\n # space matters. See above.\n module_dir_switch = None\n\n # Switch to specify where module files are searched for USE statement.\n module_include_switch = '-I' \n\n pic_flags = [] # Flags to create position-independent code\n\n src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n static_lib_format = \"lib%s%s\" # or %s%s\n shared_lib_format = \"%s%s\"\n exe_extension = \"\"\n\n ######################################################################\n ## Methods that subclasses may redefine. But don't call these methods!\n ## They are private to FCompiler class and may return unexpected\n ## results if used elsewhere. So, you have been warned..\n\n def get_version_cmd(self):\n \"\"\" Compiler command to print out version information. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n cmd = self.executables['version_cmd']\n if cmd is not None:\n cmd = cmd[0]\n if cmd==f77:\n cmd = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if cmd==f90:\n cmd = self.compiler_f90[0]\n return cmd\n\n def get_linker_so(self):\n \"\"\" Linker command to build shared libraries. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n ln = self.executables['linker_so']\n if ln is not None:\n ln = ln[0]\n if ln==f77:\n ln = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if ln==f90:\n ln = self.compiler_f90[0]\n return ln\n\n def get_flags(self):\n \"\"\" List of flags common to all compiler types. \"\"\"\n return [] + self.pic_flags\n def get_flags_version(self):\n \"\"\" List of compiler flags to print out version information. \"\"\"\n if self.executables['version_cmd']:\n return self.executables['version_cmd'][1:]\n return []\n def get_flags_f77(self):\n \"\"\" List of Fortran 77 specific flags. \"\"\"\n if self.executables['compiler_f77']:\n return self.executables['compiler_f77'][1:]\n return []\n def get_flags_f90(self):\n \"\"\" List of Fortran 90 specific flags. \"\"\"\n if self.executables['compiler_f90']:\n return self.executables['compiler_f90'][1:]\n return []\n def get_flags_fix(self):\n \"\"\" List of Fortran 90 fixed format specific flags. \"\"\"\n if self.executables['compiler_fix']:\n return self.executables['compiler_fix'][1:]\n return []\n def get_flags_linker_so(self):\n \"\"\" List of linker flags to build a shared library. \"\"\"\n if self.executables['linker_so']:\n return self.executables['linker_so'][1:]\n return []\n def get_flags_ar(self):\n \"\"\" List of archiver flags. \"\"\"\n if self.executables['archiver']:\n return self.executables['archiver'][1:]\n return []\n def get_flags_opt(self):\n \"\"\" List of architecture independent compiler flags. \"\"\"\n return []\n def get_flags_arch(self):\n \"\"\" List of architecture dependent compiler flags. \"\"\"\n return []\n def get_flags_debug(self):\n \"\"\" List of compiler flags to compile with debugging information. \"\"\"\n return []\n get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt\n get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch\n get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug\n\n def get_libraries(self):\n \"\"\" List of compiler libraries. \"\"\"\n return self.libraries[:]\n def get_library_dirs(self):\n \"\"\" List of compiler library directories. \"\"\"\n return self.library_dirs[:]\n\n ############################################################\n\n ## Public methods:\n\n def customize(self, dist=None):\n \"\"\" Customize Fortran compiler.\n\n This method gets Fortran compiler specific information from\n (i) class definition, (ii) environment, (iii) distutils config\n files, and (iv) command line.\n\n This method should be always called after constructing a\n compiler instance. But not in __init__ because Distribution\n instance is needed for (iii) and (iv).\n \"\"\"\n log.info('customize %s' % (self.__class__.__name__))\n if dist is None:\n # These hooks are for testing only!\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n conf = dist.get_option_dict('config_fc')\n\n noopt = conf.get('noopt',[None,0])[1]\n noarch = conf.get('noarch',[None,noopt])[1]\n debug = conf.get('debug',[None,0])[1]\n\n f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))\n f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))\n # Temporarily setting f77,f90 compilers so that\n # version_cmd can use their executables.\n if f77:\n self.set_executables(compiler_f77=[f77])\n if f90:\n self.set_executables(compiler_f90=[f90])\n\n # Must set version_cmd before others as self.get_flags*\n # methods may call self.get_version.\n vers_cmd = self.__get_cmd(self.get_version_cmd)\n if vers_cmd:\n vflags = self.__get_flags(self.get_flags_version)\n self.set_executables(version_cmd=[vers_cmd]+vflags)\n\n if f77:\n f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',\n (conf,'f77flags'))\n if f90:\n f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',\n (conf,'f90flags'))\n\n # XXX Assuming that free format is default for f90 compiler.\n fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))\n if fix:\n fixflags = self.__get_flags(self.get_flags_fix) + f90flags\n\n oflags,aflags,dflags = [],[],[]\n if not noopt:\n oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))\n if f77 and self.get_flags_opt is not self.get_flags_opt_f77:\n f77flags += self.__get_flags(self.get_flags_opt_f77)\n if f90 and self.get_flags_opt is not self.get_flags_opt_f90:\n f90flags += self.__get_flags(self.get_flags_opt_f90)\n if fix and self.get_flags_opt is not self.get_flags_opt_f90:\n fixflags += self.__get_flags(self.get_flags_opt_f90)\n if not noarch:\n aflags = self.__get_flags(self.get_flags_arch,'FARCH',\n (conf,'arch'))\n if f77 and self.get_flags_arch is not self.get_flags_arch_f77:\n f77flags += self.__get_flags(self.get_flags_arch_f77)\n if f90 and self.get_flags_arch is not self.get_flags_arch_f90:\n f90flags += self.__get_flags(self.get_flags_arch_f90)\n if fix and self.get_flags_arch is not self.get_flags_arch_f90:\n fixflags += self.__get_flags(self.get_flags_arch_f90)\n if debug:\n dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')\n if f77 and self.get_flags_debug is not self.get_flags_debug_f77:\n f77flags += self.__get_flags(self.get_flags_debug_f77)\n if f90 and self.get_flags_debug is not self.get_flags_debug_f90:\n f90flags += self.__get_flags(self.get_flags_debug_f90)\n if fix and self.get_flags_debug is not self.get_flags_debug_f90:\n fixflags += self.__get_flags(self.get_flags_debug_f90)\n\n fflags = self.__get_flags(self.get_flags,'FFLAGS') \\\n + dflags + oflags + aflags\n\n if f77:\n self.set_executables(compiler_f77=[f77]+f77flags+fflags)\n if f90:\n self.set_executables(compiler_f90=[f90]+f90flags+fflags)\n if fix:\n self.set_executables(compiler_fix=[fix]+fixflags+fflags)\n\n #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS\n linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')\n if linker_so:\n linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')\n self.set_executables(linker_so=[linker_so]+linker_so_flags)\n\n ar = self.__get_cmd('archiver','AR')\n if ar:\n arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')\n self.set_executables(archiver=[ar]+arflags)\n\n ranlib = self.__get_cmd('ranlib','RANLIB')\n if ranlib:\n self.set_executables(ranlib=[ranlib])\n\n self.set_library_dirs(self.get_library_dirs())\n self.set_libraries(self.get_libraries())\n\n verbose = conf.get('verbose',[None,0])[1]\n if verbose:\n self.dump_properties()\n return\n\n def dump_properties(self):\n \"\"\" Print out the attributes of a compiler instance. \"\"\"\n props = []\n for key in self.executables.keys() + \\\n ['version','libraries','library_dirs',\n 'object_switch','compile_switch']:\n if hasattr(self,key):\n v = getattr(self,key)\n props.append((key, None, '= '+`v`))\n props.sort()\n\n pretty_printer = FancyGetopt(props)\n for l in pretty_printer.generate_help(\"%s instance properties:\" \\\n % (self.__class__.__name__)):\n if l[:4]==' --':\n l = ' ' + l[4:]\n print l\n return\n\n ###################\n\n def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):\n \"\"\"Compile 'src' to product 'obj'.\"\"\"\n if is_f_file(src):\n flavor = ':f77'\n compiler = self.compiler_f77\n elif is_free_format(src):\n flavor = ':f90'\n compiler = self.compiler_f90\n if compiler is None:\n raise DistutilsExecError, 'f90 not supported by '\\\n +self.__class__.__name__\n else:\n flavor = ':fix'\n compiler = self.compiler_fix\n if compiler is None:\n raise DistutilsExecError, 'f90 (fixed) not supported by '\\\n +self.__class__.__name__\n if self.object_switch[-1]==' ':\n o_args = [self.object_switch.strip(),obj]\n else:\n o_args = [self.object_switch.strip()+obj]\n\n assert self.compile_switch.strip()\n s_args = [self.compile_switch, src]\n\n if os.name == 'nt':\n compiler = _nt_quote_args(compiler)\n command = compiler + cc_args + s_args + o_args + extra_postargs\n\n display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,\n src)\n try:\n self.spawn(command,display=display)\n except DistutilsExecError, msg:\n raise CompileError, msg\n\n return\n\n def module_options(self, module_dirs, module_build_dir):\n options = []\n if self.module_dir_switch is not None:\n if self.module_dir_switch[-1]==' ':\n options.extend([self.module_dir_switch.strip(),module_build_dir])\n else:\n options.append(self.module_dir_switch.strip()+module_build_dir)\n else:\n print 'XXX: module_build_dir=%r option ignored' % (module_build_dir)\n print 'XXX: Fix module_dir_switch for ',self.__class__.__name__\n if self.module_include_switch is not None:\n for d in [module_build_dir]+module_dirs:\n options.append('%s%s' % (self.module_include_switch, d))\n else:\n print 'XXX: module_dirs=%r option ignored' % (module_dirs)\n print 'XXX: Fix module_include_switch for ',self.__class__.__name__\n return options\n\n def library_option(self, lib):\n return \"-l\" + lib\n def library_dir_option(self, dir):\n return \"-L\" + dir\n\n# def _get_cc_args(self, pp_opts, debug, extra_preargs):\n# return []\n\n if sys.version[:3]<'2.3':\n def compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if output_dir is None: output_dir = self.output_dir\n if macros is None: macros = self.macros\n elif type(macros) is ListType: macros = macros + (self.macros or [])\n if include_dirs is None: include_dirs = self.include_dirs\n elif type(include_dirs) in (ListType, TupleType):\n include_dirs = list(include_dirs) + (self.include_dirs or [])\n if extra_preargs is None: extra_preargs=[]\n from distutils.sysconfig import python_build\n objects = self.object_filenames(sources,strip_dir=python_build,\n output_dir=output_dir)\n from distutils.ccompiler import gen_preprocess_options\n pp_opts = gen_preprocess_options(macros, include_dirs)\n build = {}\n for i in range(len(sources)):\n src,obj = sources[i],objects[i]\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n def detect_language(self, sources):\n return\n\n def link(self, target_desc, objects,\n output_filename, output_dir=None, libraries=None,\n library_dirs=None, runtime_library_dirs=None,\n export_symbols=None, debug=0, extra_preargs=None,\n extra_postargs=None, build_temp=None, target_lang=None):\n objects, output_dir = self._fix_object_args(objects, output_dir)\n libraries, library_dirs, runtime_library_dirs = \\\n self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)\n\n lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,\n libraries)\n if type(output_dir) not in (StringType, NoneType):\n raise TypeError, \"'output_dir' must be a string or None\"\n if output_dir is not None:\n output_filename = os.path.join(output_dir, output_filename)\n\n if self._need_link(objects, output_filename):\n if self.library_switch[-1]==' ':\n o_args = [self.library_switch.strip(),output_filename]\n else:\n o_args = [self.library_switch.strip()+output_filename]\n ld_args = (objects + self.objects +\n lib_opts + o_args)\n if debug:\n ld_args[:0] = ['-g']\n if extra_preargs:\n ld_args[:0] = extra_preargs\n if extra_postargs:\n ld_args.extend(extra_postargs)\n self.mkpath(os.path.dirname(output_filename))\n if target_desc == CCompiler.EXECUTABLE:\n raise NotImplementedError,self.__class__.__name__+'.linker_exe attribute'\n else:\n linker = self.linker_so[:]\n if os.name == 'nt':\n linker = _nt_quote_args(linker)\n command = linker + ld_args\n try:\n self.spawn(command)\n except DistutilsExecError, msg:\n raise LinkError, msg\n else:\n log.debug(\"skipping %s (up-to-date)\", output_filename)\n return\n\n ############################################################\n\n ## Private methods:\n\n def __get_cmd(self, command, envvar=None, confvar=None):\n if command is None:\n var = None\n elif type(command) is type(''):\n var = self.executables[command]\n if var is not None:\n var = var[0]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n return var\n\n def __get_flags(self, command, envvar=None, confvar=None):\n if command is None:\n var = []\n elif type(command) is type(''):\n var = self.executables[command][1:]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n if type(var) is type(''):\n var = split_quoted(var)\n return var\n\n ## class FCompiler\n\n##############################################################################\n\nfcompiler_class = {'gnu':('gnufcompiler','GnuFCompiler',\n \"GNU Fortran Compiler\"),\n 'pg':('pgfcompiler','PGroupFCompiler',\n \"Portland Group Fortran Compiler\"),\n 'absoft':('absoftfcompiler','AbsoftFCompiler',\n \"Absoft Corp Fortran Compiler\"),\n 'mips':('mipsfcompiler','MipsFCompiler',\n \"MIPSpro Fortran Compiler\"),\n 'sun':('sunfcompiler','SunFCompiler',\n \"Sun|Forte Fortran 95 Compiler\"),\n 'intel':('intelfcompiler','IntelFCompiler',\n \"Intel Fortran Compiler for 32-bit apps\"),\n 'intelv':('intelfcompiler','IntelVisualFCompiler',\n \"Intel Visual Fortran Compiler for 32-bit apps\"),\n 'intele':('intelfcompiler','IntelItaniumFCompiler',\n \"Intel Fortran Compiler for Itanium apps\"),\n 'intelev':('intelfcompiler','IntelItaniumVisualFCompiler',\n \"Intel Visual Fortran Compiler for Itanium apps\"),\n 'nag':('nagfcompiler','NAGFCompiler',\n \"NAGWare Fortran 95 Compiler\"),\n 'compaq':('compaqfcompiler','CompaqFCompiler',\n \"Compaq Fortran Compiler\"),\n 'compaqv':('compaqfcompiler','CompaqVisualFCompiler',\n \"DIGITAL|Compaq Visual Fortran Compiler\"),\n 'vast':('vastfcompiler','VastFCompiler',\n \"Pacific-Sierra Research Fortran 90 Compiler\"),\n 'hpux':('hpuxfcompiler','HPUXFCompiler',\n \"HP Fortran 90 Compiler\"),\n 'lahey':('laheyfcompiler','LaheyFCompiler',\n \"Lahey/Fujitsu Fortran 95 Compiler\"),\n 'ibm':('ibmfcompiler','IbmFCompiler',\n \"IBM XL Fortran Compiler\"),\n 'f':('fcompiler','FFCompiler',\n \"Fortran Company/NAG F Compiler\"),\n }\n\n_default_compilers = (\n # Platform mappings\n ('win32',('gnu','intelv','absoft','compaqv','intelev')),\n ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev')),\n ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',\n 'intele')),\n ('darwin.*',('nag','absoft','ibm','gnu')),\n ('sunos.*',('forte','gnu','sun')),\n ('irix.*',('mips','gnu')),\n ('aix.*',('ibm','gnu')),\n # OS mappings\n ('posix',('gnu',)),\n ('nt',('gnu',)),\n ('mac',('gnu',)),\n )\n\ndef _find_existing_fcompiler(compilers, osname=None, platform=None):\n for compiler in compilers:\n v = None\n try:\n c = new_fcompiler(plat=platform, compiler=compiler)\n c.customize()\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is not None:\n return compiler\n return\n\ndef get_default_fcompiler(osname=None, platform=None):\n \"\"\" Determine the default Fortran compiler to use for the given platform. \"\"\"\n if osname is None:\n osname = os.name\n if platform is None:\n platform = sys.platform\n matching_compilers = []\n for pattern, compiler in _default_compilers:\n if re.match(pattern, platform) is not None or \\\n re.match(pattern, osname) is not None:\n if type(compiler) is type(()):\n matching_compilers.extend(list(compiler))\n else:\n matching_compilers.append(compiler)\n if not matching_compilers:\n matching_compilers.append('gnu')\n compiler = _find_existing_fcompiler(matching_compilers,\n osname=osname,\n platform=platform)\n if compiler is not None:\n return compiler\n return matching_compilers[0]\n\ndef new_fcompiler(plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n \"\"\" Generate an instance of some FCompiler subclass for the supplied\n platform/compiler combination.\n \"\"\"\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_fcompiler(plat)\n (module_name, class_name, long_description) = fcompiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile Fortran code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler.\" % compiler\n msg = msg + \" Supported compilers are: %s)\" \\\n % (','.join(fcompiler_class.keys()))\n raise DistutilsPlatformError, msg\n\n try:\n module_name = 'scipy_distutils.'+module_name\n __import__ (module_name)\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile Fortran code: unable to load module '%s'\" % \\\n module_name\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile Fortran code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\ndef show_fcompilers(dist = None):\n \"\"\" Print list of available compilers (used by the \"--help-fcompiler\"\n option to \"config_fc\").\n \"\"\"\n if dist is None:\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n compilers = []\n compilers_na = []\n compilers_ni = []\n for compiler in fcompiler_class.keys():\n v = 'N/A'\n try:\n c = new_fcompiler(compiler=compiler)\n c.customize(dist)\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is None:\n compilers_na.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n elif v=='N/A':\n compilers_ni.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n else:\n compilers.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2] + ' (%s)' % v))\n compilers.sort()\n compilers_na.sort()\n pretty_printer = FancyGetopt(compilers)\n pretty_printer.print_help(\"List of available Fortran compilers:\")\n pretty_printer = FancyGetopt(compilers_na)\n pretty_printer.print_help(\"List of unavailable Fortran compilers:\")\n if compilers_ni:\n pretty_printer = FancyGetopt(compilers_ni)\n pretty_printer.print_help(\"List of unimplemented Fortran compilers:\")\n print \"For compiler details, run 'config_fc --verbose' setup command.\"\n\ndef dummy_fortran_file():\n import tempfile\n dummy_name = tempfile.mktemp()+'__dummy'\n dummy = open(dummy_name+'.f','w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n save_th = log._global_log.threshold\n log.set_threshold(log_threshold)\n try: os.remove(name+'.f'); log.debug('removed '+name+'.f')\n except OSError: pass\n try: os.remove(name+'.o'); log.debug('removed '+name+'.o')\n except OSError: pass\n log.set_threshold(save_th)\n atexit.register(rm_file)\n return dummy_name\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*][^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\nif __name__ == '__main__':\n show_fcompilers()\n", "methods": [ { "name": "get_version_cmd", "long_name": "get_version_cmd( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 188, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 206, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 224, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_version", "long_name": "get_flags_version( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 227, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_ar", "long_name": "get_flags_ar( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 257, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 260, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 270, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 273, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "customize", "long_name": "customize( self , dist = None )", "filename": "fcompiler.py", "nloc": 84, "complexity": 36, "token_count": 799, "parameters": [ "self", "dist" ], "start_line": 281, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 115, "top_nesting_level": 1 }, { "name": "dump_properties", "long_name": "dump_properties( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 5, "token_count": 117, "parameters": [ "self" ], "start_line": 397, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "_compile", "long_name": "_compile( self , obj , src , ext , cc_args , extra_postargs , pp_opts )", "filename": "fcompiler.py", "nloc": 32, "complexity": 8, "token_count": 211, "parameters": [ "self", "obj", "src", "ext", "cc_args", "extra_postargs", "pp_opts" ], "start_line": 418, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "module_options", "long_name": "module_options( self , module_dirs , module_build_dir )", "filename": "fcompiler.py", "nloc": 17, "complexity": 5, "token_count": 129, "parameters": [ "self", "module_dirs", "module_build_dir" ], "start_line": 456, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "library_option", "long_name": "library_option( self , lib )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "lib" ], "start_line": 474, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "library_dir_option", "long_name": "library_dir_option( self , dir )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "dir" ], "start_line": 476, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 256, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 483, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 }, { "name": "detect_language", "long_name": "detect_language( self , sources )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self", "sources" ], "start_line": 508, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir = None , libraries = None , library_dirs = None , runtime_library_dirs = None , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "fcompiler.py", "nloc": 42, "complexity": 11, "token_count": 306, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 511, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 1 }, { "name": "__get_cmd", "long_name": "__get_cmd( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 110, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 560, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__get_flags", "long_name": "__get_flags( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 120, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 575, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "_find_existing_fcompiler", "long_name": "_find_existing_fcompiler( compilers , osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 5, "token_count": 71, "parameters": [ "compilers", "osname", "platform" ], "start_line": 646, "end_line": 659, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_default_fcompiler", "long_name": "get_default_fcompiler( osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 21, "complexity": 9, "token_count": 135, "parameters": [ "osname", "platform" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "new_fcompiler", "long_name": "new_fcompiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "fcompiler.py", "nloc": 34, "complexity": 7, "token_count": 182, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 684, "end_line": 721, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "show_fcompilers", "long_name": "show_fcompilers( dist = None )", "filename": "fcompiler.py", "nloc": 41, "complexity": 8, "token_count": 261, "parameters": [ "dist" ], "start_line": 723, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "dummy_fortran_file.rm_file", "long_name": "dummy_fortran_file.rm_file( name = dummy_name , log_threshold = log . _global_log . threshold )", "filename": "fcompiler.py", "nloc": 8, "complexity": 3, "token_count": 84, "parameters": [ "name", "log_threshold" ], "start_line": 775, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "dummy_fortran_file", "long_name": "dummy_fortran_file( )", "filename": "fcompiler.py", "nloc": 9, "complexity": 1, "token_count": 46, "parameters": [], "start_line": 769, "end_line": 784, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "is_free_format", "long_name": "is_free_format( file )", "filename": "fcompiler.py", "nloc": 19, "complexity": 9, "token_count": 114, "parameters": [ "file" ], "start_line": 790, "end_line": 811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_version_cmd", "long_name": "get_version_cmd( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 188, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 206, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 224, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_version", "long_name": "get_flags_version( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 227, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_ar", "long_name": "get_flags_ar( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 257, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 260, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 270, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 273, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "customize", "long_name": "customize( self , dist = None )", "filename": "fcompiler.py", "nloc": 84, "complexity": 36, "token_count": 799, "parameters": [ "self", "dist" ], "start_line": 281, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 115, "top_nesting_level": 1 }, { "name": "dump_properties", "long_name": "dump_properties( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 5, "token_count": 117, "parameters": [ "self" ], "start_line": 397, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "_compile", "long_name": "_compile( self , obj , src , ext , cc_args , extra_postargs , pp_opts )", "filename": "fcompiler.py", "nloc": 32, "complexity": 8, "token_count": 211, "parameters": [ "self", "obj", "src", "ext", "cc_args", "extra_postargs", "pp_opts" ], "start_line": 418, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "module_options", "long_name": "module_options( self , module_dirs , module_build_dir )", "filename": "fcompiler.py", "nloc": 17, "complexity": 5, "token_count": 129, "parameters": [ "self", "module_dirs", "module_build_dir" ], "start_line": 456, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "library_option", "long_name": "library_option( self , lib )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "lib" ], "start_line": 474, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "library_dir_option", "long_name": "library_dir_option( self , dir )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "dir" ], "start_line": 476, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 256, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 483, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 }, { "name": "detect_language", "long_name": "detect_language( self , sources )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self", "sources" ], "start_line": 508, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir = None , libraries = None , library_dirs = None , runtime_library_dirs = None , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "fcompiler.py", "nloc": 42, "complexity": 11, "token_count": 306, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 511, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 1 }, { "name": "__get_cmd", "long_name": "__get_cmd( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 110, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 560, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__get_flags", "long_name": "__get_flags( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 120, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 575, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "_find_existing_fcompiler", "long_name": "_find_existing_fcompiler( compilers , osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 5, "token_count": 71, "parameters": [ "compilers", "osname", "platform" ], "start_line": 646, "end_line": 659, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_default_fcompiler", "long_name": "get_default_fcompiler( osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 21, "complexity": 9, "token_count": 135, "parameters": [ "osname", "platform" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "new_fcompiler", "long_name": "new_fcompiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "fcompiler.py", "nloc": 34, "complexity": 7, "token_count": 182, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 684, "end_line": 721, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "show_fcompilers", "long_name": "show_fcompilers( dist = None )", "filename": "fcompiler.py", "nloc": 41, "complexity": 8, "token_count": 261, "parameters": [ "dist" ], "start_line": 723, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "dummy_fortran_file.rm_file", "long_name": "dummy_fortran_file.rm_file( name = dummy_name , log_threshold = log . _global_log . threshold )", "filename": "fcompiler.py", "nloc": 8, "complexity": 3, "token_count": 84, "parameters": [ "name", "log_threshold" ], "start_line": 775, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "dummy_fortran_file", "long_name": "dummy_fortran_file( )", "filename": "fcompiler.py", "nloc": 9, "complexity": 1, "token_count": 46, "parameters": [], "start_line": 769, "end_line": 784, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "is_free_format", "long_name": "is_free_format( file )", "filename": "fcompiler.py", "nloc": 19, "complexity": 9, "token_count": 114, "parameters": [ "file" ], "start_line": 790, "end_line": 811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 606, "complexity": 163, "token_count": 4083, "diff_parsed": { "added": [ "_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match" ], "deleted": [ "_free_f90_start = re.compile(r'[^c*][^\\s\\d\\t]',re.I).match" ] } }, { "old_path": null, "new_path": "scipy_distutils/tests/f2py_f90_ext/include/body.f90", "filename": "body.f90", "extension": "f90", "change_type": "ADD", "diff": "@@ -0,0 +1,5 @@\n+ subroutine bar13(a)\n+ !f2py intent(out) a\n+ integer a\n+ a = 13\n+ end subroutine bar13\n", "added_lines": 5, "deleted_lines": 0, "source_code": " subroutine bar13(a)\n !f2py intent(out) a\n integer a\n a = 13\n end subroutine bar13\n", "source_code_before": null, "methods": [ { "name": "bar13", "long_name": "bar13( a )", "filename": "body.f90", "nloc": 4, "complexity": 1, "token_count": 10, "parameters": [ "a" ], "start_line": 1, "end_line": 5, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "bar13", "long_name": "bar13( a )", "filename": "body.f90", "nloc": 4, "complexity": 1, "token_count": 10, "parameters": [ "a" ], "start_line": 1, "end_line": 5, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 4, "complexity": 1, "token_count": 12, "diff_parsed": { "added": [ " subroutine bar13(a)", " !f2py intent(out) a", " integer a", " a = 13", " end subroutine bar13" ], "deleted": [] } }, { "old_path": "scipy_distutils/tests/f2py_f90_ext/setup.py", "new_path": "scipy_distutils/tests/f2py_f90_ext/setup.py", "filename": "setup.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -4,7 +4,9 @@\n \n package = 'f2py_f90_ext'\n \n-ext = Extension(package+'.foo',['src/foo_free.f90'])\n+ext = Extension(package+'.foo',['src/foo_free.f90'],\n+ include_dirs=['include'],\n+ f2py_options=['--include_paths','include'])\n \n setup(\n name = package,\n", "added_lines": 3, "deleted_lines": 1, "source_code": "\nimport os\nfrom scipy_distutils.core import setup, Extension\n\npackage = 'f2py_f90_ext'\n\next = Extension(package+'.foo',['src/foo_free.f90'],\n include_dirs=['include'],\n f2py_options=['--include_paths','include'])\n\nsetup(\n name = package,\n ext_modules = [ext],\n packages = [package+'.tests',package],\n package_dir = {package:'.'})\n\n", "source_code_before": "\nimport os\nfrom scipy_distutils.core import setup, Extension\n\npackage = 'f2py_f90_ext'\n\next = Extension(package+'.foo',['src/foo_free.f90'])\n\nsetup(\n name = package,\n ext_modules = [ext],\n packages = [package+'.tests',package],\n package_dir = {package:'.'})\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 11, "complexity": 0, "token_count": 69, "diff_parsed": { "added": [ "ext = Extension(package+'.foo',['src/foo_free.f90'],", " include_dirs=['include'],", " f2py_options=['--include_paths','include'])" ], "deleted": [ "ext = Extension(package+'.foo',['src/foo_free.f90'])" ] } }, { "old_path": "scipy_distutils/tests/f2py_f90_ext/src/foo_free.f90", "new_path": "scipy_distutils/tests/f2py_f90_ext/src/foo_free.f90", "filename": "foo_free.f90", "extension": "f90", "change_type": "MODIFY", "diff": "@@ -1,8 +1,6 @@\n module foo_free\n contains\n- subroutine bar13(a)\n- !f2py intent(out) a\n- integer a\n- a = 13\n- end subroutine bar13\n+\n+include \"body.f90\"\n+\n end module foo_free\n", "added_lines": 3, "deleted_lines": 5, "source_code": "module foo_free\ncontains\n\ninclude \"body.f90\"\n\nend module foo_free\n", "source_code_before": "module foo_free\ncontains\n subroutine bar13(a)\n !f2py intent(out) a\n integer a\n a = 13\n end subroutine bar13\nend module foo_free\n", "methods": [], "methods_before": [ { "name": "foo_free::bar13", "long_name": "foo_free::bar13( a )", "filename": "foo_free.f90", "nloc": 4, "complexity": 1, "token_count": 10, "parameters": [ "a" ], "start_line": 3, "end_line": 7, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "foo_free::bar13", "long_name": "foo_free::bar13( a )", "filename": "foo_free.f90", "nloc": 4, "complexity": 1, "token_count": 10, "parameters": [ "a" ], "start_line": 3, "end_line": 7, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "nloc": 3, "complexity": 0, "token_count": 6, "diff_parsed": { "added": [ "", "include \"body.f90\"", "" ], "deleted": [ " subroutine bar13(a)", " !f2py intent(out) a", " integer a", " a = 13", " end subroutine bar13" ] } } ] }, { "hash": "f7a8b6da0e2f067bb584303923f24214769cf6af", "msg": "Disabled status=998 error for now.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-29T19:17:15+00:00", "author_timezone": 0, "committer_date": "2004-03-29T19:17:15+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "766c97f887162de06ca60caedbb28252499e464d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 1, "insertions": 4, "lines": 5, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -420,7 +420,10 @@ def _exec_command( command, use_shell=None, **env ):\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n- status = 998\n+ # Not sure how to handle the case where errmess\n+ # contains only warning messages and that should\n+ # be treated as errors.\n+ #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n", "added_lines": 4, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 165, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 243, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 294, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 439, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 515, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 563, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 581, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 165, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 243, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 294, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 555, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 96, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 } ], "nloc": 420, "complexity": 134, "token_count": 3329, "diff_parsed": { "added": [ " # Not sure how to handle the case where errmess", " # contains only warning messages and that should", " # be treated as errors.", " #status = 998" ], "deleted": [ " status = 998" ] } } ] }, { "hash": "6fc96bc3f0ddd57c59f25c29077dbbfecb92f81b", "msg": "Introduced recursive keyword 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-03-29T23:24:56+00:00", "author_timezone": 0, "committer_date": "2004-03-29T23:24:56+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f7a8b6da0e2f067bb584303923f24214769cf6af" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 4, "insertions": 22, "lines": 26, "files": 1, "dmm_unit_size": 0.6923076923076923, "dmm_unit_complexity": 0.6923076923076923, "dmm_unit_interfacing": 0.6923076923076923, "modified_files": [ { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,3 +1,4 @@\n+\n import os,sys,string\n import re\n import types\n@@ -386,11 +387,22 @@ def compiler_to_string(compiler):\n lines.append(format % prop)\n return '\\n'.join(lines)\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+ 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+\n def get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n- ignore_packages=[]):\n+ ignore_packages=[],\n+ recursive=None):\n \n \"\"\"\n Return a list of configurations found in a tree of Python\n@@ -412,6 +424,9 @@ def get_subpackages(path,\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@@ -444,10 +459,13 @@ def get_subpackages(path,\n finally:\n del sys.path[0]\n \n- for package_name in include_packages:\n- dirname = os.path.join(path, package_name)\n+ if recursive:\n+ os.path.walk(path,_get_dirs_with_init, (include_packages,path))\n \n- setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\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", "added_lines": 22, "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\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_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\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\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "import os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[]):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n for package_name in include_packages:\n dirname = os.path.join(path, package_name)\n\n setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "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": 5, "token_count": 124, "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": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 196, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 210, "end_line": 215, "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": 217, "end_line": 218, "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": 220, "end_line": 235, "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": 237, "end_line": 241, "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": 243, "end_line": 246, "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": 257, "end_line": 269, "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": 270, "end_line": 271, "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": 272, "end_line": 283, "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": 284, "end_line": 285, "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": 293, "end_line": 296, "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": 297, "end_line": 298, "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": 299, "end_line": 300, "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": 309, "end_line": 325, "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": 327, "end_line": 332, "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": 334, "end_line": 339, "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": 341, "end_line": 346, "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": 348, "end_line": 368, "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": 370, "end_line": 388, "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": 390, "end_line": 398, "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": 400, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 13, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 59, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 5, "token_count": 124, "parameters": [ "mod_name", "parent_path" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 86, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 90, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 95, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 98, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 114, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 126, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 145, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 186, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 195, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 209, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "dot_join", "long_name": "dot_join( * args )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "args" ], "start_line": 216, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 219, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 236, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 242, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 256, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 269, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 271, "end_line": 282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 283, "end_line": 284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 292, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 296, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 298, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 308, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 326, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 333, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 340, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 347, "end_line": 367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 369, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 54, "complexity": 15, "token_count": 391, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 389, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 0 } ], "changed_methods": [ { "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": 400, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 54, "complexity": 15, "token_count": 391, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 389, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 0 }, { "name": "_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": 390, "end_line": 398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "nloc": 362, "complexity": 120, "token_count": 2684, "diff_parsed": { "added": [ "", "def _get_dirs_with_init((packages,path), dirname, names):", " \"\"\"Internal: used by get_subpackages.\"\"\"", " if '.svn' in names:", " del names[names.index('.svn')]", " if os.path.isfile(os.path.join(dirname,'__init__.py')):", " if path==dirname: return", " package_name = '.'.join(dirname.split(os.sep)[len(path.split(os.sep)):])", " if package_name not in packages:", " packages.append(package_name)", "", " ignore_packages=[],", " recursive=None):", "", " If recursive is True then subpackages are searched recursively", " starting from the path and added to include_packages list.", " if recursive:", " os.path.walk(path,_get_dirs_with_init, (include_packages,path))", " for package_name in include_packages:", " dirname = os.path.join(*([path]+package_name.split('.')))", " setup_file = os.path.join(dirname,\\", " 'setup_' + package_name.split('.')[-1]+'.py')" ], "deleted": [ " ignore_packages=[]):", " for package_name in include_packages:", " dirname = os.path.join(path, package_name)", " setup_file = os.path.join(dirname,'setup_' + package_name+'.py')" ] } } ] }, { "hash": "15e2818defa615d38ccfc711cd184d6e643de17e", "msg": "Fixed weave.catalog tests and trying to reduce the verbosity of weave usage.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-29T23:29:28+00:00", "author_timezone": 0, "committer_date": "2004-03-29T23:29:28+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6fc96bc3f0ddd57c59f25c29077dbbfecb92f81b" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 5, "insertions": 7, "lines": 12, "files": 2, "dmm_unit_size": 0.3333333333333333, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.3333333333333333, "modified_files": [ { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -211,6 +211,8 @@ def build_extension(module_path,compiler_name = '',build_dir = None,\n success = 0\n try:\n from scipy_distutils.core import setup, Extension\n+ from scipy_distutils.log import set_verbosity\n+ set_verbosity(-1)\n except ImportError:\n from distutils.core import setup, Extension\n \n", "added_lines": 2, "deleted_lines": 0, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\nimport commands\n\nimport platform_info\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\nimport distutils.dir_util\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n \n\n if (sys.platform == 'darwin'):\n # The Jaguar distributed python 2.2 has -arch i386 in the link line\n # which doesn't seem right. It omits all kinds of warnings, so \n # remove it.\n ld = ld.replace('-arch i386','')\n \n # The following line is a HACK to fix a problem with building the\n # freetype shared library under Mac OS X:\n ld += ' -framework AppKit'\n \n # 2.3a1 on OS X emits a ton of warnings about long double. OPT\n # appears to not have all the needed flags set while CFLAGS does.\n cfg_vars = distutils.sysconfig._config_vars\n cfg_vars['OPT'] = cfg_vars['CFLAGS'] \n distutils.sysconfig._config_vars['LDSHARED'] = ld \n \ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n\n\ndef create_extension(module_path, **kw):\n \"\"\" Create an Extension that can be buil by setup.py\n \n See build_extension for information on keyword arguments.\n \"\"\"\n # some (most?) platforms will fail to link C++ correctly\n # unless scipy_distutils is used.\n try:\n from scipy_distutils.core import Extension\n except ImportError:\n from distutils.core import Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # the business end of the function\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n #--------------------------------------------------------------------\n # added access to environment variable that user can set to specify\n # where python (and other) include files are located. This is \n # very useful on systems where python is installed by the root, but\n # the user has also installed numerous packages in their own \n # location.\n #--------------------------------------------------------------------\n if os.environ.has_key('PYTHONINCLUDE'):\n path_string = os.environ['PYTHONINCLUDE'] \n if sys.platform == \"win32\":\n extra_include_dirs = path_string.split(';')\n else: \n extra_include_dirs = path_string.split(':')\n include_dirs = kw.get('include_dirs',[])\n kw['include_dirs'] = include_dirs + extra_include_dirs\n\n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n return ext \n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n try:\n from scipy_distutils.core import setup, Extension\n from scipy_distutils.log import set_verbosity\n set_verbosity(-1)\n except ImportError:\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n # dag. We keep having to add directories to the path to keep \n # object files separated from each other. gcc2.x and gcc3.x C++ \n # object files are not compatible, so we'll stick them in a sub\n # dir based on their version. This will add an md5 check sum\n # of the compiler binary to the directory name to keep objects\n # from different compilers in different locations.\n \n compiler_dir = platform_info.get_compiler_dir(compiler_name)\n temp_dir = os.path.join(temp_dir,compiler_dir)\n distutils.dir_util.mkpath(temp_dir)\n \n compiler_name = choose_compiler(compiler_name)\n \n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1:\n verb = 1 \n else:\n verb = 0\n \n t1 = time.time() \n ext = create_extension(module_path,**kw)\n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n\n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\n \ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n from distutils.version import StrictVersion\n from distutils.ccompiler import gen_preprocess_options, gen_lib_options\n from distutils.errors import DistutilsExecError, CompileError, UnknownFileError\n \n from distutils.unixccompiler import UnixCCompiler \n \n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, \n verbose,dry_run, force)\n \n # we need to support 3.2 which doesn't match the standard\n # get_versions methods regex\n if self.gcc_version is None:\n import re\n out = os.popen('gcc' + ' -dumpversion','r')\n out_string = out.read()\n out.close()\n result = re.search('(\\d+\\.\\d+)',out_string)\n if result:\n self.gcc_version = StrictVersion(result.group(1)) \n\n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n\n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n if self.gcc_version <= \"3.0.0\":\n self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n compiler_so='gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n else: \n self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n compiler_so='gcc -O2 -w -Wstrict-prototypes',\n linker_exe='g++ ',\n linker_so='g++ -shared')\n # added for python2.3 support\n # we can't pass it through set_executables because pre 2.2 would fail\n self.compiler_cxx = ['g++']\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n\n def link(self,\n target_desc,\n objects,\n output_filename,\n output_dir,\n libraries,\n library_dirs,\n runtime_library_dirs,\n export_symbols=None, # export_symbols, we do this in our def-file\n debug=0,\n extra_preargs=None,\n extra_postargs=None,\n build_temp=None,\n target_lang=None):\n if self.gcc_version < \"3.0.0\":\n distutils.cygwinccompiler.CygwinCCompiler.link(self,\n target_desc,\n objects,\n output_filename,\n output_dir,\n libraries,\n library_dirs,\n runtime_library_dirs,\n None, # export_symbols, we do this in our def-file\n debug,\n extra_preargs,\n extra_postargs,\n build_temp,\n target_lang)\n else:\n UnixCCompiler.link(self,\n target_desc,\n objects,\n output_filename,\n output_dir,\n libraries,\n library_dirs,\n runtime_library_dirs,\n None, # export_symbols, we do this in our def-file\n debug,\n extra_preargs,\n extra_postargs,\n build_temp,\n target_lang)\n\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n from scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\nimport commands\n\nimport platform_info\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\nimport distutils.dir_util\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n \n\n if (sys.platform == 'darwin'):\n # The Jaguar distributed python 2.2 has -arch i386 in the link line\n # which doesn't seem right. It omits all kinds of warnings, so \n # remove it.\n ld = ld.replace('-arch i386','')\n \n # The following line is a HACK to fix a problem with building the\n # freetype shared library under Mac OS X:\n ld += ' -framework AppKit'\n \n # 2.3a1 on OS X emits a ton of warnings about long double. OPT\n # appears to not have all the needed flags set while CFLAGS does.\n cfg_vars = distutils.sysconfig._config_vars\n cfg_vars['OPT'] = cfg_vars['CFLAGS'] \n distutils.sysconfig._config_vars['LDSHARED'] = ld \n \ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n\n\ndef create_extension(module_path, **kw):\n \"\"\" Create an Extension that can be buil by setup.py\n \n See build_extension for information on keyword arguments.\n \"\"\"\n # some (most?) platforms will fail to link C++ correctly\n # unless scipy_distutils is used.\n try:\n from scipy_distutils.core import Extension\n except ImportError:\n from distutils.core import Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # the business end of the function\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n #--------------------------------------------------------------------\n # added access to environment variable that user can set to specify\n # where python (and other) include files are located. This is \n # very useful on systems where python is installed by the root, but\n # the user has also installed numerous packages in their own \n # location.\n #--------------------------------------------------------------------\n if os.environ.has_key('PYTHONINCLUDE'):\n path_string = os.environ['PYTHONINCLUDE'] \n if sys.platform == \"win32\":\n extra_include_dirs = path_string.split(';')\n else: \n extra_include_dirs = path_string.split(':')\n include_dirs = kw.get('include_dirs',[])\n kw['include_dirs'] = include_dirs + extra_include_dirs\n\n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n return ext \n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n try:\n from scipy_distutils.core import setup, Extension\n except ImportError:\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n # dag. We keep having to add directories to the path to keep \n # object files separated from each other. gcc2.x and gcc3.x C++ \n # object files are not compatible, so we'll stick them in a sub\n # dir based on their version. This will add an md5 check sum\n # of the compiler binary to the directory name to keep objects\n # from different compilers in different locations.\n \n compiler_dir = platform_info.get_compiler_dir(compiler_name)\n temp_dir = os.path.join(temp_dir,compiler_dir)\n distutils.dir_util.mkpath(temp_dir)\n \n compiler_name = choose_compiler(compiler_name)\n \n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1:\n verb = 1 \n else:\n verb = 0\n \n t1 = time.time() \n ext = create_extension(module_path,**kw)\n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n\n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\n \ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n from distutils.version import StrictVersion\n from distutils.ccompiler import gen_preprocess_options, gen_lib_options\n from distutils.errors import DistutilsExecError, CompileError, UnknownFileError\n \n from distutils.unixccompiler import UnixCCompiler \n \n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, \n verbose,dry_run, force)\n \n # we need to support 3.2 which doesn't match the standard\n # get_versions methods regex\n if self.gcc_version is None:\n import re\n out = os.popen('gcc' + ' -dumpversion','r')\n out_string = out.read()\n out.close()\n result = re.search('(\\d+\\.\\d+)',out_string)\n if result:\n self.gcc_version = StrictVersion(result.group(1)) \n\n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n\n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n if self.gcc_version <= \"3.0.0\":\n self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n compiler_so='gcc -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n else: \n self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n compiler_so='gcc -O2 -w -Wstrict-prototypes',\n linker_exe='g++ ',\n linker_so='g++ -shared')\n # added for python2.3 support\n # we can't pass it through set_executables because pre 2.2 would fail\n self.compiler_cxx = ['g++']\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n\n def link(self,\n target_desc,\n objects,\n output_filename,\n output_dir,\n libraries,\n library_dirs,\n runtime_library_dirs,\n export_symbols=None, # export_symbols, we do this in our def-file\n debug=0,\n extra_preargs=None,\n extra_postargs=None,\n build_temp=None,\n target_lang=None):\n if self.gcc_version < \"3.0.0\":\n distutils.cygwinccompiler.CygwinCCompiler.link(self,\n target_desc,\n objects,\n output_filename,\n output_dir,\n libraries,\n library_dirs,\n runtime_library_dirs,\n None, # export_symbols, we do this in our def-file\n debug,\n extra_preargs,\n extra_postargs,\n build_temp,\n target_lang)\n else:\n UnixCCompiler.link(self,\n target_desc,\n objects,\n output_filename,\n output_dir,\n libraries,\n library_dirs,\n runtime_library_dirs,\n None, # export_symbols, we do this in our def-file\n debug,\n extra_preargs,\n extra_postargs,\n build_temp,\n target_lang)\n\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n from scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 13, "complexity": 3, "token_count": 95, "parameters": [], "start_line": 33, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "create_extension", "long_name": "create_extension( module_path , ** kw )", "filename": "build_tools.py", "nloc": 30, "complexity": 7, "token_count": 258, "parameters": [ "module_path", "kw" ], "start_line": 71, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 52, "complexity": 8, "token_count": 341, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 127, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 166, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 295, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 307, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 310, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 318, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 341, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 363, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( command )", "filename": "build_tools.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 383, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 393, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 409, "end_line": 434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 37, "complexity": 8, "token_count": 212, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 452, "end_line": 515, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir , libraries , library_dirs , runtime_library_dirs , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "build_tools.py", "nloc": 44, "complexity": 2, "token_count": 120, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 519, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 573, "end_line": 581, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 583, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 13, "complexity": 3, "token_count": 95, "parameters": [], "start_line": 33, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "create_extension", "long_name": "create_extension( module_path , ** kw )", "filename": "build_tools.py", "nloc": 30, "complexity": 7, "token_count": 258, "parameters": [ "module_path", "kw" ], "start_line": 71, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 50, "complexity": 8, "token_count": 330, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 127, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 164, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 293, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 305, "end_line": 306, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 308, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 316, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 339, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 361, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( command )", "filename": "build_tools.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 381, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 391, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 407, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 37, "complexity": 8, "token_count": 212, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 450, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir , libraries , library_dirs , runtime_library_dirs , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "build_tools.py", "nloc": 44, "complexity": 2, "token_count": 120, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 517, "end_line": 560, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 571, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 581, "end_line": 607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 52, "complexity": 8, "token_count": 341, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 127, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 166, "top_nesting_level": 0 } ], "nloc": 336, "complexity": 67, "token_count": 1966, "diff_parsed": { "added": [ " from scipy_distutils.log import set_verbosity", " set_verbosity(-1)" ], "deleted": [] } }, { "old_path": "weave/catalog.py", "new_path": "weave/catalog.py", "filename": "catalog.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -259,14 +259,14 @@ def get_catalog(module_path,mode='r'):\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n- try:\n- # code reliant on the fact that we are using dumbdbm\n- if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):\n+ if (dumb and os.path.exists(catalog_file+'.dat')) \\\n+ or os.path.exists(catalog_file):\n+ sh = shelve.open(catalog_file,mode)\n+ else:\n+ if mode=='r':\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n- except: # not sure how to pin down which error to catch yet\n- sh = None\n return sh\n \n class catalog:\n", "added_lines": 5, "deleted_lines": 5, "source_code": "\"\"\" Track relationships between compiled extension functions & code fragments\n\n catalog keeps track of which compiled(or even standard) functions are \n related to which code fragments. It also stores these relationships\n to disk so they are remembered between Python sessions. When \n \n a = 1\n compiler.inline('printf(\"printed from C: %d\",a);',['a'] )\n \n is called, inline() first looks to see if it has seen the code \n 'printf(\"printed from C\");' before. If not, it calls \n \n catalog.get_functions('printf(\"printed from C: %d\", a);')\n \n which returns a list of all the function objects that have been compiled\n for the code fragment. Multiple functions can occur because the code\n could be compiled for different types for 'a' (although not likely in\n this case). The catalog first looks in its cache and quickly returns\n a list of the functions if possible. If the cache lookup fails, it then\n looks through possibly multiple catalog files on disk and fills its\n cache with all the functions that match the code fragment. \n \n In case where the code fragment hasn't been compiled, inline() compiles\n the code and then adds it to the catalog:\n \n function = \n catalog.add_function('printf(\"printed from C: %d\", a);',function)\n \n add_function() adds function to the front of the cache. function,\n along with the path information to its module, are also stored in a\n persistent catalog for future use by python sessions. \n\"\"\" \n\nimport os,sys,string\nimport pickle\nimport tempfile\n\ntry:\n import dbhash\n import shelve\n dumb = 0\nexcept ImportError:\n import dumb_shelve as shelve\n dumb = 1\n\n#For testing...\n#import dumb_shelve as shelve\n#dumb = 1\n\n#import shelve\n#dumb = 0\n \ndef getmodule(object):\n \"\"\" Discover the name of the module where object was defined.\n \n This is an augmented version of inspect.getmodule that can discover \n the parent module for extension functions.\n \"\"\"\n import inspect\n value = inspect.getmodule(object)\n if value is None:\n #walk trough all modules looking for function\n for name,mod in sys.modules.items():\n # try except used because of some comparison failures\n # in wxPoint code. Need to review this\n try:\n if mod and object in mod.__dict__.values():\n value = mod\n # if it is a built-in module, keep looking to see\n # if a non-builtin also has it. Otherwise quit and\n # consider the module found. (ain't perfect, but will \n # have to do for now).\n if string.find('(built-in)',str(mod)) is -1:\n break\n \n except (TypeError, KeyError, ImportError):\n pass \n return value\n\ndef expr_to_filename(expr):\n \"\"\" Convert an arbitrary expr string to a valid file name.\n \n The name is based on the md5 check sum for the string and\n Something that was a little more human readable would be \n nice, but the computer doesn't seem to care.\n \"\"\"\n import md5\n base = 'sc_'\n return base + md5.new(expr).hexdigest()\n\ndef unique_file(d,expr):\n \"\"\" Generate a unqiue file name based on expr in directory d\n \n This is meant for use with building extension modules, so\n a file name is considered unique if none of the following\n extension '.cpp','.o','.so','module.so','.py', or '.pyd'\n exists in directory d. The fully qualified path to the\n new name is returned. You'll need to append your own\n extension to it before creating files.\n \"\"\"\n files = os.listdir(d)\n #base = 'scipy_compile'\n base = expr_to_filename(expr)\n for i in range(1000000):\n fname = base + `i`\n if not (fname+'.cpp' in files or\n fname+'.o' in files or\n fname+'.so' in files or\n fname+'module.so' in files or\n fname+'.py' in files or\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n\ndef create_dir(p):\n \"\"\" Create a directory and any necessary intermediate directories.\"\"\"\n if not os.path.exists(p):\n try:\n os.mkdir(p)\n except OSError:\n # perhaps one or more intermediate path components don't exist\n # try to create them\n base,dir = os.path.split(p)\n create_dir(base)\n # don't enclose this one in try/except - we want the user to\n # get failure info\n os.mkdir(p)\n\ndef is_writable(dir):\n dummy = os.path.join(dir, \"dummy\")\n try:\n open(dummy, 'w')\n except IOError:\n return 0\n os.unlink(dummy)\n return 1\n\ndef whoami():\n \"\"\"return a string identifying the user.\"\"\"\n return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"\n\ndef default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n XX is the Python version number in all paths listed below\n On windows, the default location is the temporary directory\n returned by gettempdir()/pythonXX.\n \n On Unix, ~/.pythonXX_compiled is the default location. If it doesn't\n exist, it is created. The directory is marked rwx------.\n \n If for some reason it isn't possible to build a default directory\n in the user's home, /tmp/_pythonXX_compiled is used. If it \n doesn't exist, it is created. The directory is marked rwx------\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n path = os.path.join(os.environ['HOME'],'.' + python_name)\n except KeyError:\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n \n # add a subdirectory for the OS.\n # It might be better to do this at a different location so that\n # it wasn't only the default directory that gets this behavior. \n #path = os.path.join(path,sys.platform)\n else:\n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n \n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\ndef intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n if not os.path.exists(path):\n create_dir(path)\n return path\n \ndef default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\n \ndef os_dependent_catalog_name():\n \"\"\" Generate catalog name dependent on OS and Python version being used.\n \n This allows multiple platforms to have catalog files in the\n same directory without stepping on each other. For now, it \n bases the name of the value returned by sys.platform and the\n version of python being run. If this isn't enough to descriminate\n on some platforms, we can try to add other info. It has \n occured to me that if we get fancy enough to optimize for different\n architectures, then chip type might be added to the catalog name also.\n \"\"\"\n version = '%d%d' % sys.version_info[:2]\n return sys.platform+version+'compiled_catalog'\n \ndef catalog_path(module_path):\n \"\"\" Return the full path name for the catalog file in the given directory.\n \n module_path can either be a file name or a path name. If it is a \n file name, the catalog file name in its parent directory is returned.\n If it is a directory, the catalog file in that directory is returned.\n\n If module_path doesn't exist, None is returned. Note though, that the\n catalog file does *not* have to exist, only its parent. '~', shell\n variables, and relative ('.' and '..') paths are all acceptable.\n \n catalog file names are os dependent (based on sys.platform), so this \n should support multiple platforms sharing the same disk space \n (NFS mounts). See os_dependent_catalog_name() for more info.\n \"\"\"\n module_path = os.path.expanduser(module_path)\n module_path = os.path.expandvars(module_path)\n module_path = os.path.abspath(module_path)\n if not os.path.exists(module_path):\n catalog_file = None\n elif not os.path.isdir(module_path):\n module_path,dummy = os.path.split(module_path)\n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n else: \n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n return catalog_file\n\ndef get_catalog(module_path,mode='r'):\n \"\"\" Return a function catalog (shelve object) from the path module_path\n\n If module_path is a directory, the function catalog returned is\n from that directory. If module_path is an actual module_name,\n then the function catalog returned is from its parent directory.\n mode uses the standard 'c' = create, 'n' = new, 'r' = read, \n 'w' = write file open modes available for anydbm databases.\n \n Well... it should be. Stuck with dumbdbm for now and the modes\n almost don't matter. We do some checking for 'r' mode, but that\n is about it.\n \n See catalog_path() for more information on module_path.\n \"\"\"\n if mode not in ['c','r','w','n']:\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n if (dumb and os.path.exists(catalog_file+'.dat')) \\\n or os.path.exists(catalog_file):\n sh = shelve.open(catalog_file,mode)\n else:\n if mode=='r':\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n return sh\n\nclass catalog:\n \"\"\" Stores information about compiled functions both in cache and on disk.\n \n catalog stores (code, list_of_function) pairs so that all the functions\n that have been compiled for code are available for calling (usually in\n inline or blitz).\n \n catalog keeps a dictionary of previously accessed code values cached \n for quick access. It also handles the looking up of functions compiled \n in previously called Python sessions on disk in function catalogs. \n catalog searches the directories in the PYTHONCOMPILED environment \n variable in order loading functions that correspond to the given code \n fragment. A default directory is also searched for catalog functions. \n On unix, the default directory is usually '~/.pythonxx_compiled' where \n xx is the version of Python used. On windows, it is the directory \n returned by temfile.gettempdir(). Functions closer to the front are of \n the variable list are guaranteed to be closer to the front of the \n function list so that they will be called first. See \n get_cataloged_functions() for more info on how the search order is \n traversed.\n \n Catalog also handles storing information about compiled functions to\n a catalog. When writing this information, the first writable catalog\n file in PYTHONCOMPILED path is used. If a writable catalog is not\n found, it is written to the catalog in the default directory. This\n directory should always be writable.\n \"\"\"\n def __init__(self,user_path_list=None):\n \"\"\" Create a catalog for storing/searching for compiled functions. \n \n user_path_list contains directories that should be searched \n first for function catalogs. They will come before the path\n entries in the PYTHONCOMPILED environment varilable.\n \"\"\"\n if type(user_path_list) == type('string'):\n self.user_path_list = [user_path_list]\n elif user_path_list:\n self.user_path_list = user_path_list\n else:\n self.user_path_list = []\n self.cache = {}\n self.module_dir = None\n self.paths_added = 0\n \n def set_module_directory(self,module_dir):\n \"\"\" Set the path that will replace 'MODULE' in catalog searches.\n \n You should call clear_module_directory() when your finished\n working with it.\n \"\"\"\n self.module_dir = module_dir\n def get_module_directory(self):\n \"\"\" Return the path used to replace the 'MODULE' in searches.\n \"\"\"\n return self.module_dir\n def clear_module_directory(self):\n \"\"\" Reset 'MODULE' path to None so that it is ignored in searches. \n \"\"\"\n self.module_dir = None\n \n def get_environ_path(self):\n \"\"\" Return list of paths from 'PYTHONCOMPILED' environment variable.\n \n On Unix the path in PYTHONCOMPILED is a ':' separated list of\n directories. On Windows, a ';' separated list is used. \n \"\"\"\n paths = []\n if os.environ.has_key('PYTHONCOMPILED'):\n path_string = os.environ['PYTHONCOMPILED'] \n if sys.platform == 'win32':\n #probably should also look in registry\n paths = path_string.split(';')\n else: \n paths = path_string.split(':')\n return paths \n\n def build_search_order(self):\n \"\"\" Returns a list of paths that are searched for catalogs. \n \n Values specified in the catalog constructor are searched first,\n then values found in the PYTHONCOMPILED environment variable.\n The directory returned by default_dir() is always returned at\n the end of the list.\n \n There is a 'magic' path name called 'MODULE' that is replaced\n by the directory defined by set_module_directory(). If the\n module directory hasn't been set, 'MODULE' is ignored.\n \"\"\"\n \n paths = self.user_path_list + self.get_environ_path()\n search_order = []\n for path in paths:\n if path == 'MODULE':\n if self.module_dir:\n search_order.append(self.module_dir)\n else:\n search_order.append(path)\n search_order.append(default_dir())\n return search_order\n\n def get_catalog_files(self):\n \"\"\" Returns catalog file list in correct search order.\n \n Some of the catalog files may not currently exists.\n However, all will be valid locations for a catalog\n to be created (if you have write permission).\n \"\"\"\n files = map(catalog_path,self.build_search_order())\n files = filter(lambda x: x is not None,files)\n return files\n\n def get_existing_files(self):\n \"\"\" Returns all existing catalog file list in correct search order.\n \"\"\"\n files = self.get_catalog_files()\n # open every stinking file to check if it exists.\n # This is because anydbm doesn't provide a consistent naming \n # convention across platforms for its files \n existing_files = []\n for file in files:\n if get_catalog(os.path.dirname(file),'r') is not None:\n existing_files.append(file)\n # This is the non-portable (and much faster) old code\n #existing_files = filter(os.path.exists,files)\n return existing_files\n\n def get_writable_file(self,existing_only=0):\n \"\"\" Return the name of the first writable catalog file.\n \n Its parent directory must also be writable. This is so that\n compiled modules can be written to the same directory.\n \"\"\"\n # note: both file and its parent directory must be writeable\n if existing_only:\n files = self.get_existing_files()\n else:\n files = self.get_catalog_files()\n # filter for (file exists and is writable) OR directory is writable\n def file_test(x):\n from os import access, F_OK, W_OK\n return (access(x,F_OK) and access(x,W_OK) or\n access(os.path.dirname(x),W_OK))\n writable = filter(file_test,files)\n if writable:\n file = writable[0]\n else:\n file = None\n return file\n \n def get_writable_dir(self):\n \"\"\" Return the parent directory of first writable catalog file.\n \n The returned directory has write access.\n \"\"\"\n return os.path.dirname(self.get_writable_file())\n \n def unique_module_name(self,code,module_dir=None):\n \"\"\" Return full path to unique file name that in writable location.\n \n The directory for the file is the first writable directory in \n the catalog search path. The unique file name is derived from\n the code fragment. If, module_dir is specified, it is used\n to replace 'MODULE' in the search path.\n \"\"\"\n if module_dir is not None:\n self.set_module_directory(module_dir)\n try:\n d = self.get_writable_dir()\n finally:\n if module_dir is not None:\n self.clear_module_directory()\n return unique_file(d,code)\n\n def path_key(self,code):\n \"\"\" Return key for path information for functions associated with code.\n \"\"\"\n return '__path__' + code\n \n def configure_path(self,cat,code):\n \"\"\" Add the python path for the given code to the sys.path\n \n unconfigure_path() should be called as soon as possible after\n imports associated with code are finished so that sys.path \n is restored to normal.\n \"\"\"\n try:\n paths = cat[self.path_key(code)]\n self.paths_added = len(paths)\n sys.path = paths + sys.path\n except:\n self.paths_added = 0 \n \n def unconfigure_path(self):\n \"\"\" Restores sys.path to normal after calls to configure_path()\n \n Remove the previously added paths from sys.path\n \"\"\"\n sys.path = sys.path[self.paths_added:]\n self.paths_added = 0\n\n def get_cataloged_functions(self,code):\n \"\"\" Load all functions associated with code from catalog search path.\n \n Sometimes there can be trouble loading a function listed in a\n catalog file because the actual module that holds the function \n has been moved or deleted. When this happens, that catalog file\n is \"repaired\", meaning the entire entry for this function is \n removed from the file. This only affects the catalog file that\n has problems -- not the others in the search path.\n \n The \"repair\" behavior may not be needed, but I'll keep it for now.\n \"\"\"\n mode = 'r'\n cat = None\n function_list = []\n for path in self.build_search_order():\n cat = get_catalog(path,mode)\n if cat is not None and cat.has_key(code):\n # set up the python path so that modules for this\n # function can be loaded.\n self.configure_path(cat,code)\n try: \n function_list += cat[code]\n except: #SystemError and ImportError so far seen \n # problems loading a function from the catalog. Try to\n # repair the cause.\n cat.close()\n self.repair_catalog(path,code)\n self.unconfigure_path() \n return function_list\n\n\n def repair_catalog(self,catalog_path,code):\n \"\"\" Remove entry for code from catalog_path\n \n Occasionally catalog entries could get corrupted. An example\n would be when a module that had functions in the catalog was\n deleted or moved on the disk. The best current repair method is \n just to trash the entire catalog entry for this piece of code. \n This may loose function entries that are valid, but thats life.\n \n catalog_path must be writable for repair. If it isn't, the\n function exists with a warning. \n \"\"\"\n writable_cat = None\n if not os.path.exists(catalog_path):\n return\n try:\n writable_cat = get_catalog(catalog_path,'w')\n except:\n print 'warning: unable to repair catalog entry\\n %s\\n in\\n %s' % \\\n (code,catalog_path)\n return \n if writable_cat.has_key(code):\n print 'repairing catalog by removing key'\n del writable_cat[code]\n \n # it is possible that the path key doesn't exist (if the function registered\n # was a built-in function), so we have to check if the path exists before\n # arbitrarily deleting it.\n path_key = self.path_key(code) \n if writable_cat.has_key(path_key):\n del writable_cat[path_key] \n \n def get_functions_fast(self,code):\n \"\"\" Return list of functions for code from the cache.\n \n Return an empty list if the code entry is not found.\n \"\"\"\n return self.cache.get(code,[])\n \n def get_functions(self,code,module_dir=None):\n \"\"\" Return the list of functions associated with this code fragment.\n \n The cache is first searched for the function. If an entry\n in the cache is not found, then catalog files on disk are \n searched for the entry. This is slooooow, but only happens\n once per code object. All the functions found in catalog files\n on a cache miss are loaded into the cache to speed up future calls.\n The search order is as follows:\n \n 1. user specified path (from catalog initialization)\n 2. directories from the PYTHONCOMPILED environment variable\n 3. The temporary directory on your platform.\n\n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n # Fast!! try cache first.\n if self.cache.has_key(code):\n return self.cache[code]\n \n # 2. Slow!! read previously compiled functions from disk.\n try:\n self.set_module_directory(module_dir)\n function_list = self.get_cataloged_functions(code)\n # put function_list in cache to save future lookups.\n if function_list:\n self.cache[code] = function_list\n # return function_list, empty or otherwise.\n finally:\n self.clear_module_directory()\n return function_list\n\n def add_function(self,code,function,module_dir=None):\n \"\"\" Adds a function to the catalog.\n \n The function is added to the cache as well as the first\n writable file catalog found in the search path. If no\n code entry exists in the cache, the on disk catalogs\n are loaded into the cache and function is added to the\n beginning of the function list.\n \n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n\n # 1. put it in the cache.\n if self.cache.has_key(code):\n if function not in self.cache[code]:\n self.cache[code].insert(0,function)\n else:\n # if it is in the cache, then it is also\n # been persisted \n return\n else: \n # Load functions and put this one up front\n self.cache[code] = self.get_functions(code) \n self.fast_cache(code,function)\n # 2. Store the function entry to disk. \n try:\n self.set_module_directory(module_dir)\n self.add_function_persistent(code,function)\n finally:\n self.clear_module_directory()\n \n def add_function_persistent(self,code,function):\n \"\"\" Store the code->function relationship to disk.\n \n Two pieces of information are needed for loading functions\n from disk -- the function pickle (which conveniently stores\n the module name, etc.) and the path to its module's directory.\n The latter is needed so that the function can be loaded no\n matter what the user's Python path is.\n \"\"\" \n # add function to data in first writable catalog\n mode = 'c' # create if doesn't exist, otherwise, use existing\n cat_dir = self.get_writable_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir() \n cat_file = catalog_path(cat_dir)\n print 'problems with default catalog -- removing'\n import glob\n files = glob.glob(cat_file+'*')\n for f in files:\n os.remove(f)\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n raise ValueError, 'Failed to access a catalog for storing functions' \n # Prabhu was getting some corrupt catalog errors. I'll put a try/except\n # to protect against this, but should really try and track down the issue.\n function_list = [function]\n try:\n function_list = function_list + cat.get(code,[])\n except pickle.UnpicklingError:\n pass\n cat[code] = function_list\n # now add needed path information for loading function\n module = getmodule(function)\n try:\n # built in modules don't have the __file__ extension, so this\n # will fail. Just pass in this case since path additions aren't\n # needed for built-in modules.\n mod_path,f=os.path.split(os.path.abspath(module.__file__))\n pkey = self.path_key(code)\n cat[pkey] = [mod_path] + cat.get(pkey,[])\n except:\n pass\n\tcat.close()\n\n def fast_cache(self,code,function):\n \"\"\" Move function to the front of the cache entry for code\n \n If future calls to the function have the same type signature,\n this will speed up access significantly because the first\n function call is correct.\n \n Note: The cache added to the inline_tools module is significantly\n faster than always calling get_functions, so this isn't\n as necessary as it used to be. Still, it's probably worth\n doing. \n \"\"\"\n try:\n if self.cache[code][0] == function:\n return\n except: # KeyError, IndexError \n pass\n try:\n self.cache[code].remove(function)\n except ValueError:\n pass\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n", "source_code_before": "\"\"\" Track relationships between compiled extension functions & code fragments\n\n catalog keeps track of which compiled(or even standard) functions are \n related to which code fragments. It also stores these relationships\n to disk so they are remembered between Python sessions. When \n \n a = 1\n compiler.inline('printf(\"printed from C: %d\",a);',['a'] )\n \n is called, inline() first looks to see if it has seen the code \n 'printf(\"printed from C\");' before. If not, it calls \n \n catalog.get_functions('printf(\"printed from C: %d\", a);')\n \n which returns a list of all the function objects that have been compiled\n for the code fragment. Multiple functions can occur because the code\n could be compiled for different types for 'a' (although not likely in\n this case). The catalog first looks in its cache and quickly returns\n a list of the functions if possible. If the cache lookup fails, it then\n looks through possibly multiple catalog files on disk and fills its\n cache with all the functions that match the code fragment. \n \n In case where the code fragment hasn't been compiled, inline() compiles\n the code and then adds it to the catalog:\n \n function = \n catalog.add_function('printf(\"printed from C: %d\", a);',function)\n \n add_function() adds function to the front of the cache. function,\n along with the path information to its module, are also stored in a\n persistent catalog for future use by python sessions. \n\"\"\" \n\nimport os,sys,string\nimport pickle\nimport tempfile\n\ntry:\n import dbhash\n import shelve\n dumb = 0\nexcept ImportError:\n import dumb_shelve as shelve\n dumb = 1\n\n#For testing...\n#import dumb_shelve as shelve\n#dumb = 1\n\n#import shelve\n#dumb = 0\n \ndef getmodule(object):\n \"\"\" Discover the name of the module where object was defined.\n \n This is an augmented version of inspect.getmodule that can discover \n the parent module for extension functions.\n \"\"\"\n import inspect\n value = inspect.getmodule(object)\n if value is None:\n #walk trough all modules looking for function\n for name,mod in sys.modules.items():\n # try except used because of some comparison failures\n # in wxPoint code. Need to review this\n try:\n if mod and object in mod.__dict__.values():\n value = mod\n # if it is a built-in module, keep looking to see\n # if a non-builtin also has it. Otherwise quit and\n # consider the module found. (ain't perfect, but will \n # have to do for now).\n if string.find('(built-in)',str(mod)) is -1:\n break\n \n except (TypeError, KeyError, ImportError):\n pass \n return value\n\ndef expr_to_filename(expr):\n \"\"\" Convert an arbitrary expr string to a valid file name.\n \n The name is based on the md5 check sum for the string and\n Something that was a little more human readable would be \n nice, but the computer doesn't seem to care.\n \"\"\"\n import md5\n base = 'sc_'\n return base + md5.new(expr).hexdigest()\n\ndef unique_file(d,expr):\n \"\"\" Generate a unqiue file name based on expr in directory d\n \n This is meant for use with building extension modules, so\n a file name is considered unique if none of the following\n extension '.cpp','.o','.so','module.so','.py', or '.pyd'\n exists in directory d. The fully qualified path to the\n new name is returned. You'll need to append your own\n extension to it before creating files.\n \"\"\"\n files = os.listdir(d)\n #base = 'scipy_compile'\n base = expr_to_filename(expr)\n for i in range(1000000):\n fname = base + `i`\n if not (fname+'.cpp' in files or\n fname+'.o' in files or\n fname+'.so' in files or\n fname+'module.so' in files or\n fname+'.py' in files or\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n\ndef create_dir(p):\n \"\"\" Create a directory and any necessary intermediate directories.\"\"\"\n if not os.path.exists(p):\n try:\n os.mkdir(p)\n except OSError:\n # perhaps one or more intermediate path components don't exist\n # try to create them\n base,dir = os.path.split(p)\n create_dir(base)\n # don't enclose this one in try/except - we want the user to\n # get failure info\n os.mkdir(p)\n\ndef is_writable(dir):\n dummy = os.path.join(dir, \"dummy\")\n try:\n open(dummy, 'w')\n except IOError:\n return 0\n os.unlink(dummy)\n return 1\n\ndef whoami():\n \"\"\"return a string identifying the user.\"\"\"\n return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"\n\ndef default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n XX is the Python version number in all paths listed below\n On windows, the default location is the temporary directory\n returned by gettempdir()/pythonXX.\n \n On Unix, ~/.pythonXX_compiled is the default location. If it doesn't\n exist, it is created. The directory is marked rwx------.\n \n If for some reason it isn't possible to build a default directory\n in the user's home, /tmp/_pythonXX_compiled is used. If it \n doesn't exist, it is created. The directory is marked rwx------\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n path = os.path.join(os.environ['HOME'],'.' + python_name)\n except KeyError:\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n \n # add a subdirectory for the OS.\n # It might be better to do this at a different location so that\n # it wasn't only the default directory that gets this behavior. \n #path = os.path.join(path,sys.platform)\n else:\n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n \n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\ndef intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n if not os.path.exists(path):\n create_dir(path)\n return path\n \ndef default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\n \ndef os_dependent_catalog_name():\n \"\"\" Generate catalog name dependent on OS and Python version being used.\n \n This allows multiple platforms to have catalog files in the\n same directory without stepping on each other. For now, it \n bases the name of the value returned by sys.platform and the\n version of python being run. If this isn't enough to descriminate\n on some platforms, we can try to add other info. It has \n occured to me that if we get fancy enough to optimize for different\n architectures, then chip type might be added to the catalog name also.\n \"\"\"\n version = '%d%d' % sys.version_info[:2]\n return sys.platform+version+'compiled_catalog'\n \ndef catalog_path(module_path):\n \"\"\" Return the full path name for the catalog file in the given directory.\n \n module_path can either be a file name or a path name. If it is a \n file name, the catalog file name in its parent directory is returned.\n If it is a directory, the catalog file in that directory is returned.\n\n If module_path doesn't exist, None is returned. Note though, that the\n catalog file does *not* have to exist, only its parent. '~', shell\n variables, and relative ('.' and '..') paths are all acceptable.\n \n catalog file names are os dependent (based on sys.platform), so this \n should support multiple platforms sharing the same disk space \n (NFS mounts). See os_dependent_catalog_name() for more info.\n \"\"\"\n module_path = os.path.expanduser(module_path)\n module_path = os.path.expandvars(module_path)\n module_path = os.path.abspath(module_path)\n if not os.path.exists(module_path):\n catalog_file = None\n elif not os.path.isdir(module_path):\n module_path,dummy = os.path.split(module_path)\n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n else: \n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n return catalog_file\n\ndef get_catalog(module_path,mode='r'):\n \"\"\" Return a function catalog (shelve object) from the path module_path\n\n If module_path is a directory, the function catalog returned is\n from that directory. If module_path is an actual module_name,\n then the function catalog returned is from its parent directory.\n mode uses the standard 'c' = create, 'n' = new, 'r' = read, \n 'w' = write file open modes available for anydbm databases.\n \n Well... it should be. Stuck with dumbdbm for now and the modes\n almost don't matter. We do some checking for 'r' mode, but that\n is about it.\n \n See catalog_path() for more information on module_path.\n \"\"\"\n if mode not in ['c','r','w','n']:\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n try:\n # code reliant on the fact that we are using dumbdbm\n if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n except: # not sure how to pin down which error to catch yet\n sh = None\n return sh\n\nclass catalog:\n \"\"\" Stores information about compiled functions both in cache and on disk.\n \n catalog stores (code, list_of_function) pairs so that all the functions\n that have been compiled for code are available for calling (usually in\n inline or blitz).\n \n catalog keeps a dictionary of previously accessed code values cached \n for quick access. It also handles the looking up of functions compiled \n in previously called Python sessions on disk in function catalogs. \n catalog searches the directories in the PYTHONCOMPILED environment \n variable in order loading functions that correspond to the given code \n fragment. A default directory is also searched for catalog functions. \n On unix, the default directory is usually '~/.pythonxx_compiled' where \n xx is the version of Python used. On windows, it is the directory \n returned by temfile.gettempdir(). Functions closer to the front are of \n the variable list are guaranteed to be closer to the front of the \n function list so that they will be called first. See \n get_cataloged_functions() for more info on how the search order is \n traversed.\n \n Catalog also handles storing information about compiled functions to\n a catalog. When writing this information, the first writable catalog\n file in PYTHONCOMPILED path is used. If a writable catalog is not\n found, it is written to the catalog in the default directory. This\n directory should always be writable.\n \"\"\"\n def __init__(self,user_path_list=None):\n \"\"\" Create a catalog for storing/searching for compiled functions. \n \n user_path_list contains directories that should be searched \n first for function catalogs. They will come before the path\n entries in the PYTHONCOMPILED environment varilable.\n \"\"\"\n if type(user_path_list) == type('string'):\n self.user_path_list = [user_path_list]\n elif user_path_list:\n self.user_path_list = user_path_list\n else:\n self.user_path_list = []\n self.cache = {}\n self.module_dir = None\n self.paths_added = 0\n \n def set_module_directory(self,module_dir):\n \"\"\" Set the path that will replace 'MODULE' in catalog searches.\n \n You should call clear_module_directory() when your finished\n working with it.\n \"\"\"\n self.module_dir = module_dir\n def get_module_directory(self):\n \"\"\" Return the path used to replace the 'MODULE' in searches.\n \"\"\"\n return self.module_dir\n def clear_module_directory(self):\n \"\"\" Reset 'MODULE' path to None so that it is ignored in searches. \n \"\"\"\n self.module_dir = None\n \n def get_environ_path(self):\n \"\"\" Return list of paths from 'PYTHONCOMPILED' environment variable.\n \n On Unix the path in PYTHONCOMPILED is a ':' separated list of\n directories. On Windows, a ';' separated list is used. \n \"\"\"\n paths = []\n if os.environ.has_key('PYTHONCOMPILED'):\n path_string = os.environ['PYTHONCOMPILED'] \n if sys.platform == 'win32':\n #probably should also look in registry\n paths = path_string.split(';')\n else: \n paths = path_string.split(':')\n return paths \n\n def build_search_order(self):\n \"\"\" Returns a list of paths that are searched for catalogs. \n \n Values specified in the catalog constructor are searched first,\n then values found in the PYTHONCOMPILED environment variable.\n The directory returned by default_dir() is always returned at\n the end of the list.\n \n There is a 'magic' path name called 'MODULE' that is replaced\n by the directory defined by set_module_directory(). If the\n module directory hasn't been set, 'MODULE' is ignored.\n \"\"\"\n \n paths = self.user_path_list + self.get_environ_path()\n search_order = []\n for path in paths:\n if path == 'MODULE':\n if self.module_dir:\n search_order.append(self.module_dir)\n else:\n search_order.append(path)\n search_order.append(default_dir())\n return search_order\n\n def get_catalog_files(self):\n \"\"\" Returns catalog file list in correct search order.\n \n Some of the catalog files may not currently exists.\n However, all will be valid locations for a catalog\n to be created (if you have write permission).\n \"\"\"\n files = map(catalog_path,self.build_search_order())\n files = filter(lambda x: x is not None,files)\n return files\n\n def get_existing_files(self):\n \"\"\" Returns all existing catalog file list in correct search order.\n \"\"\"\n files = self.get_catalog_files()\n # open every stinking file to check if it exists.\n # This is because anydbm doesn't provide a consistent naming \n # convention across platforms for its files \n existing_files = []\n for file in files:\n if get_catalog(os.path.dirname(file),'r') is not None:\n existing_files.append(file)\n # This is the non-portable (and much faster) old code\n #existing_files = filter(os.path.exists,files)\n return existing_files\n\n def get_writable_file(self,existing_only=0):\n \"\"\" Return the name of the first writable catalog file.\n \n Its parent directory must also be writable. This is so that\n compiled modules can be written to the same directory.\n \"\"\"\n # note: both file and its parent directory must be writeable\n if existing_only:\n files = self.get_existing_files()\n else:\n files = self.get_catalog_files()\n # filter for (file exists and is writable) OR directory is writable\n def file_test(x):\n from os import access, F_OK, W_OK\n return (access(x,F_OK) and access(x,W_OK) or\n access(os.path.dirname(x),W_OK))\n writable = filter(file_test,files)\n if writable:\n file = writable[0]\n else:\n file = None\n return file\n \n def get_writable_dir(self):\n \"\"\" Return the parent directory of first writable catalog file.\n \n The returned directory has write access.\n \"\"\"\n return os.path.dirname(self.get_writable_file())\n \n def unique_module_name(self,code,module_dir=None):\n \"\"\" Return full path to unique file name that in writable location.\n \n The directory for the file is the first writable directory in \n the catalog search path. The unique file name is derived from\n the code fragment. If, module_dir is specified, it is used\n to replace 'MODULE' in the search path.\n \"\"\"\n if module_dir is not None:\n self.set_module_directory(module_dir)\n try:\n d = self.get_writable_dir()\n finally:\n if module_dir is not None:\n self.clear_module_directory()\n return unique_file(d,code)\n\n def path_key(self,code):\n \"\"\" Return key for path information for functions associated with code.\n \"\"\"\n return '__path__' + code\n \n def configure_path(self,cat,code):\n \"\"\" Add the python path for the given code to the sys.path\n \n unconfigure_path() should be called as soon as possible after\n imports associated with code are finished so that sys.path \n is restored to normal.\n \"\"\"\n try:\n paths = cat[self.path_key(code)]\n self.paths_added = len(paths)\n sys.path = paths + sys.path\n except:\n self.paths_added = 0 \n \n def unconfigure_path(self):\n \"\"\" Restores sys.path to normal after calls to configure_path()\n \n Remove the previously added paths from sys.path\n \"\"\"\n sys.path = sys.path[self.paths_added:]\n self.paths_added = 0\n\n def get_cataloged_functions(self,code):\n \"\"\" Load all functions associated with code from catalog search path.\n \n Sometimes there can be trouble loading a function listed in a\n catalog file because the actual module that holds the function \n has been moved or deleted. When this happens, that catalog file\n is \"repaired\", meaning the entire entry for this function is \n removed from the file. This only affects the catalog file that\n has problems -- not the others in the search path.\n \n The \"repair\" behavior may not be needed, but I'll keep it for now.\n \"\"\"\n mode = 'r'\n cat = None\n function_list = []\n for path in self.build_search_order():\n cat = get_catalog(path,mode)\n if cat is not None and cat.has_key(code):\n # set up the python path so that modules for this\n # function can be loaded.\n self.configure_path(cat,code)\n try: \n function_list += cat[code]\n except: #SystemError and ImportError so far seen \n # problems loading a function from the catalog. Try to\n # repair the cause.\n cat.close()\n self.repair_catalog(path,code)\n self.unconfigure_path() \n return function_list\n\n\n def repair_catalog(self,catalog_path,code):\n \"\"\" Remove entry for code from catalog_path\n \n Occasionally catalog entries could get corrupted. An example\n would be when a module that had functions in the catalog was\n deleted or moved on the disk. The best current repair method is \n just to trash the entire catalog entry for this piece of code. \n This may loose function entries that are valid, but thats life.\n \n catalog_path must be writable for repair. If it isn't, the\n function exists with a warning. \n \"\"\"\n writable_cat = None\n if not os.path.exists(catalog_path):\n return\n try:\n writable_cat = get_catalog(catalog_path,'w')\n except:\n print 'warning: unable to repair catalog entry\\n %s\\n in\\n %s' % \\\n (code,catalog_path)\n return \n if writable_cat.has_key(code):\n print 'repairing catalog by removing key'\n del writable_cat[code]\n \n # it is possible that the path key doesn't exist (if the function registered\n # was a built-in function), so we have to check if the path exists before\n # arbitrarily deleting it.\n path_key = self.path_key(code) \n if writable_cat.has_key(path_key):\n del writable_cat[path_key] \n \n def get_functions_fast(self,code):\n \"\"\" Return list of functions for code from the cache.\n \n Return an empty list if the code entry is not found.\n \"\"\"\n return self.cache.get(code,[])\n \n def get_functions(self,code,module_dir=None):\n \"\"\" Return the list of functions associated with this code fragment.\n \n The cache is first searched for the function. If an entry\n in the cache is not found, then catalog files on disk are \n searched for the entry. This is slooooow, but only happens\n once per code object. All the functions found in catalog files\n on a cache miss are loaded into the cache to speed up future calls.\n The search order is as follows:\n \n 1. user specified path (from catalog initialization)\n 2. directories from the PYTHONCOMPILED environment variable\n 3. The temporary directory on your platform.\n\n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n # Fast!! try cache first.\n if self.cache.has_key(code):\n return self.cache[code]\n \n # 2. Slow!! read previously compiled functions from disk.\n try:\n self.set_module_directory(module_dir)\n function_list = self.get_cataloged_functions(code)\n # put function_list in cache to save future lookups.\n if function_list:\n self.cache[code] = function_list\n # return function_list, empty or otherwise.\n finally:\n self.clear_module_directory()\n return function_list\n\n def add_function(self,code,function,module_dir=None):\n \"\"\" Adds a function to the catalog.\n \n The function is added to the cache as well as the first\n writable file catalog found in the search path. If no\n code entry exists in the cache, the on disk catalogs\n are loaded into the cache and function is added to the\n beginning of the function list.\n \n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n\n # 1. put it in the cache.\n if self.cache.has_key(code):\n if function not in self.cache[code]:\n self.cache[code].insert(0,function)\n else:\n # if it is in the cache, then it is also\n # been persisted \n return\n else: \n # Load functions and put this one up front\n self.cache[code] = self.get_functions(code) \n self.fast_cache(code,function)\n # 2. Store the function entry to disk. \n try:\n self.set_module_directory(module_dir)\n self.add_function_persistent(code,function)\n finally:\n self.clear_module_directory()\n \n def add_function_persistent(self,code,function):\n \"\"\" Store the code->function relationship to disk.\n \n Two pieces of information are needed for loading functions\n from disk -- the function pickle (which conveniently stores\n the module name, etc.) and the path to its module's directory.\n The latter is needed so that the function can be loaded no\n matter what the user's Python path is.\n \"\"\" \n # add function to data in first writable catalog\n mode = 'c' # create if doesn't exist, otherwise, use existing\n cat_dir = self.get_writable_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir() \n cat_file = catalog_path(cat_dir)\n print 'problems with default catalog -- removing'\n import glob\n files = glob.glob(cat_file+'*')\n for f in files:\n os.remove(f)\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n raise ValueError, 'Failed to access a catalog for storing functions' \n # Prabhu was getting some corrupt catalog errors. I'll put a try/except\n # to protect against this, but should really try and track down the issue.\n function_list = [function]\n try:\n function_list = function_list + cat.get(code,[])\n except pickle.UnpicklingError:\n pass\n cat[code] = function_list\n # now add needed path information for loading function\n module = getmodule(function)\n try:\n # built in modules don't have the __file__ extension, so this\n # will fail. Just pass in this case since path additions aren't\n # needed for built-in modules.\n mod_path,f=os.path.split(os.path.abspath(module.__file__))\n pkey = self.path_key(code)\n cat[pkey] = [mod_path] + cat.get(pkey,[])\n except:\n pass\n\tcat.close()\n\n def fast_cache(self,code,function):\n \"\"\" Move function to the front of the cache entry for code\n \n If future calls to the function have the same type signature,\n this will speed up access significantly because the first\n function call is correct.\n \n Note: The cache added to the inline_tools module is significantly\n faster than always calling get_functions, so this isn't\n as necessary as it used to be. Still, it's probably worth\n doing. \n \"\"\"\n try:\n if self.cache[code][0] == function:\n return\n except: # KeyError, IndexError \n pass\n try:\n self.cache[code].remove(function)\n except ValueError:\n pass\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n", "methods": [ { "name": "getmodule", "long_name": "getmodule( object )", "filename": "catalog.py", "nloc": 13, "complexity": 7, "token_count": 81, "parameters": [ "object" ], "start_line": 53, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "expr_to_filename", "long_name": "expr_to_filename( expr )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "expr" ], "start_line": 80, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "unique_file", "long_name": "unique_file( d , expr )", "filename": "catalog.py", "nloc": 13, "complexity": 8, "token_count": 89, "parameters": [ "d", "expr" ], "start_line": 91, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "create_dir", "long_name": "create_dir( p )", "filename": "catalog.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "p" ], "start_line": 115, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "is_writable", "long_name": "is_writable( dir )", "filename": "catalog.py", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [ "dir" ], "start_line": 129, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "whoami", "long_name": "whoami( )", "filename": "catalog.py", "nloc": 2, "complexity": 3, "token_count": 25, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 17, "complexity": 5, "token_count": 141, "parameters": [], "start_line": 142, "end_line": 179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 6, "complexity": 2, "token_count": 58, "parameters": [], "start_line": 181, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 56, "parameters": [], "start_line": 191, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "os_dependent_catalog_name", "long_name": "os_dependent_catalog_name( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 202, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "catalog_path", "long_name": "catalog_path( module_path )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "module_path" ], "start_line": 216, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 14, "complexity": 6, "token_count": 97, "parameters": [ "module_path", "mode" ], "start_line": 243, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , user_path_list = None )", "filename": "catalog.py", "nloc": 10, "complexity": 3, "token_count": 60, "parameters": [ "self", "user_path_list" ], "start_line": 299, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "set_module_directory", "long_name": "set_module_directory( self , module_dir )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "module_dir" ], "start_line": 316, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_module_directory", "long_name": "get_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 323, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "clear_module_directory", "long_name": "clear_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 327, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_environ_path", "long_name": "get_environ_path( self )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 55, "parameters": [ "self" ], "start_line": 332, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "build_search_order", "long_name": "build_search_order( self )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 62, "parameters": [ "self" ], "start_line": 348, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_catalog_files", "long_name": "get_catalog_files( self )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 372, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_existing_files", "long_name": "get_existing_files( self )", "filename": "catalog.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 383, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "get_writable_file.file_test", "long_name": "get_writable_file.file_test( x )", "filename": "catalog.py", "nloc": 4, "complexity": 3, "token_count": 43, "parameters": [ "x" ], "start_line": 410, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_writable_file", "long_name": "get_writable_file( self , existing_only = 0 )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "self", "existing_only" ], "start_line": 398, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_writable_dir", "long_name": "get_writable_dir( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 421, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique_module_name", "long_name": "unique_module_name( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "self", "code", "module_dir" ], "start_line": 428, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "path_key", "long_name": "path_key( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "code" ], "start_line": 445, "end_line": 448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "configure_path", "long_name": "configure_path( self , cat , code )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "self", "cat", "code" ], "start_line": 450, "end_line": 462, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "unconfigure_path", "long_name": "unconfigure_path( self )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 464, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_cataloged_functions", "long_name": "get_cataloged_functions( self , code )", "filename": "catalog.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "self", "code" ], "start_line": 472, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "repair_catalog", "long_name": "repair_catalog( self , catalog_path , code )", "filename": "catalog.py", "nloc": 16, "complexity": 5, "token_count": 83, "parameters": [ "self", "catalog_path", "code" ], "start_line": 504, "end_line": 534, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "get_functions_fast", "long_name": "get_functions_fast( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "code" ], "start_line": 536, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_functions", "long_name": "get_functions( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 65, "parameters": [ "self", "code", "module_dir" ], "start_line": 543, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , code , function , module_dir = None )", "filename": "catalog.py", "nloc": 14, "complexity": 4, "token_count": 97, "parameters": [ "self", "code", "function", "module_dir" ], "start_line": 577, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "add_function_persistent", "long_name": "add_function_persistent( self , code , function )", "filename": "catalog.py", "nloc": 32, "complexity": 7, "token_count": 199, "parameters": [ "self", "code", "function" ], "start_line": 610, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 1 }, { "name": "fast_cache", "long_name": "fast_cache( self , code , function )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 59, "parameters": [ "self", "code", "function" ], "start_line": 658, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 } ], "methods_before": [ { "name": "getmodule", "long_name": "getmodule( object )", "filename": "catalog.py", "nloc": 13, "complexity": 7, "token_count": 81, "parameters": [ "object" ], "start_line": 53, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "expr_to_filename", "long_name": "expr_to_filename( expr )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "expr" ], "start_line": 80, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "unique_file", "long_name": "unique_file( d , expr )", "filename": "catalog.py", "nloc": 13, "complexity": 8, "token_count": 89, "parameters": [ "d", "expr" ], "start_line": 91, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "create_dir", "long_name": "create_dir( p )", "filename": "catalog.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "p" ], "start_line": 115, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "is_writable", "long_name": "is_writable( dir )", "filename": "catalog.py", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [ "dir" ], "start_line": 129, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "whoami", "long_name": "whoami( )", "filename": "catalog.py", "nloc": 2, "complexity": 3, "token_count": 25, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 17, "complexity": 5, "token_count": 141, "parameters": [], "start_line": 142, "end_line": 179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 6, "complexity": 2, "token_count": 58, "parameters": [], "start_line": 181, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 56, "parameters": [], "start_line": 191, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "os_dependent_catalog_name", "long_name": "os_dependent_catalog_name( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 202, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "catalog_path", "long_name": "catalog_path( module_path )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "module_path" ], "start_line": 216, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 13, "complexity": 6, "token_count": 80, "parameters": [ "module_path", "mode" ], "start_line": 243, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , user_path_list = None )", "filename": "catalog.py", "nloc": 10, "complexity": 3, "token_count": 60, "parameters": [ "self", "user_path_list" ], "start_line": 299, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "set_module_directory", "long_name": "set_module_directory( self , module_dir )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "module_dir" ], "start_line": 316, "end_line": 322, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_module_directory", "long_name": "get_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 323, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "clear_module_directory", "long_name": "clear_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 327, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_environ_path", "long_name": "get_environ_path( self )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 55, "parameters": [ "self" ], "start_line": 332, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "build_search_order", "long_name": "build_search_order( self )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 62, "parameters": [ "self" ], "start_line": 348, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_catalog_files", "long_name": "get_catalog_files( self )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 372, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_existing_files", "long_name": "get_existing_files( self )", "filename": "catalog.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 383, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "get_writable_file.file_test", "long_name": "get_writable_file.file_test( x )", "filename": "catalog.py", "nloc": 4, "complexity": 3, "token_count": 43, "parameters": [ "x" ], "start_line": 410, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_writable_file", "long_name": "get_writable_file( self , existing_only = 0 )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "self", "existing_only" ], "start_line": 398, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_writable_dir", "long_name": "get_writable_dir( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 421, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique_module_name", "long_name": "unique_module_name( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "self", "code", "module_dir" ], "start_line": 428, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "path_key", "long_name": "path_key( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "code" ], "start_line": 445, "end_line": 448, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "configure_path", "long_name": "configure_path( self , cat , code )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "self", "cat", "code" ], "start_line": 450, "end_line": 462, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "unconfigure_path", "long_name": "unconfigure_path( self )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 464, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_cataloged_functions", "long_name": "get_cataloged_functions( self , code )", "filename": "catalog.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "self", "code" ], "start_line": 472, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "repair_catalog", "long_name": "repair_catalog( self , catalog_path , code )", "filename": "catalog.py", "nloc": 16, "complexity": 5, "token_count": 83, "parameters": [ "self", "catalog_path", "code" ], "start_line": 504, "end_line": 534, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "get_functions_fast", "long_name": "get_functions_fast( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "code" ], "start_line": 536, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_functions", "long_name": "get_functions( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 65, "parameters": [ "self", "code", "module_dir" ], "start_line": 543, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , code , function , module_dir = None )", "filename": "catalog.py", "nloc": 14, "complexity": 4, "token_count": 97, "parameters": [ "self", "code", "function", "module_dir" ], "start_line": 577, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "add_function_persistent", "long_name": "add_function_persistent( self , code , function )", "filename": "catalog.py", "nloc": 32, "complexity": 7, "token_count": 199, "parameters": [ "self", "code", "function" ], "start_line": 610, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 1 }, { "name": "fast_cache", "long_name": "fast_cache( self , code , function )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 59, "parameters": [ "self", "code", "function" ], "start_line": 658, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 14, "complexity": 6, "token_count": 97, "parameters": [ "module_path", "mode" ], "start_line": 243, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 } ], "nloc": 364, "complexity": 106, "token_count": 2009, "diff_parsed": { "added": [ " if (dumb and os.path.exists(catalog_file+'.dat')) \\", " or os.path.exists(catalog_file):", " sh = shelve.open(catalog_file,mode)", " else:", " if mode=='r':" ], "deleted": [ " try:", " # code reliant on the fact that we are using dumbdbm", " if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):", " except: # not sure how to pin down which error to catch yet", " sh = None" ] } } ] }, { "hash": "2d7c53055afd78acfddb455173498983b8da4993", "msg": "Added .F, .F90 to the list of Fortran source extensions.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-30T16:26:15+00:00", "author_timezone": 0, "committer_date": "2004-03-30T16:26:15+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "15e2818defa615d38ccfc711cd184d6e643de17e" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 2, "insertions": 5, "lines": 7, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/fcompiler.py", "new_path": "scipy_distutils/fcompiler.py", "filename": "fcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -136,10 +136,13 @@ class FCompiler(CCompiler):\n \n language_map = {'.f':'f77',\n '.for':'f77',\n+ '.F':'f77', # XXX: needs preprocessor\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n- '.f95':'f90'}\n+ '.F90':'f90', # XXX: needs preprocessor\n+ '.f95':'f90',\n+ }\n language_order = ['f90','f77']\n \n version_pattern = None\n@@ -172,7 +175,7 @@ class FCompiler(CCompiler):\n \n pic_flags = [] # Flags to create position-independent code\n \n- src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']\n+ src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95','.F','.F90']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n", "added_lines": 5, "deleted_lines": 2, "source_code": "\"\"\"scipy_distutils.fcompiler\n\nContains FCompiler, an abstract base class that defines the interface\nfor the Scipy_distutils Fortran compiler abstraction model.\n\n\"\"\"\n\nimport re\nimport os\nimport sys\nimport atexit\nfrom types import StringType, NoneType, ListType, TupleType\nfrom glob import glob\n\nfrom distutils.version import StrictVersion\nfrom scipy_distutils.ccompiler import CCompiler, gen_lib_options\n# distutils.ccompiler provides the following functions:\n# gen_preprocess_options(macros, include_dirs)\n# gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)\nfrom distutils.errors import DistutilsModuleError,DistutilsArgError,\\\n DistutilsExecError,CompileError,LinkError,DistutilsPlatformError\nfrom distutils.core import Command\nfrom distutils.util import split_quoted\nfrom distutils.fancy_getopt import FancyGetopt\nfrom distutils.sysconfig import get_config_var\nfrom distutils.spawn import _nt_quote_args \n\n\nfrom scipy_distutils.command.config_compiler import config_fc\n\nimport log\nfrom misc_util import compiler_to_string\nfrom exec_command import find_executable, exec_command\n\nclass FCompiler(CCompiler):\n \"\"\" Abstract base class to define the interface that must be implemented\n by real Fortran compiler classes.\n\n Methods that subclasses may redefine:\n\n get_version_cmd(), get_linker_so(), get_version()\n get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()\n get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),\n get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),\n get_flags_arch_f90(), get_flags_debug_f90(),\n get_flags_fix(), get_flags_linker_so(), get_flags_version()\n\n DON'T call these methods (except get_version) after\n constructing a compiler instance or inside any other method.\n All methods, except get_version_cmd() and get_flags_version(), may\n call get_version() method.\n\n After constructing a compiler instance, always call customize(dist=None)\n method that finalizes compiler construction and makes the following\n attributes available:\n compiler_f77\n compiler_f90\n compiler_fix\n linker_so\n archiver\n ranlib\n libraries\n library_dirs\n \"\"\"\n # CCompiler defines the following attributes:\n # compiler_type\n # src_extensions\n # obj_extension\n # static_lib_extension\n # shared_lib_extension\n # static_lib_format\n # shared_lib_format\n # exe_extension\n # language_map ### REDEFINED\n # language_order ### REDEFINED\n # and the following public methods:\n # set_executables(**args)\n # set_executable(key,value)\n # define_macro(name, value=None)\n # undefine_macro(name)\n # add_include_dir(dir)\n # set_include_dirs(dirs)\n # add_library(libname)\n # set_libraries(libnames)\n # add_library_dir(dir)\n # set_library_dirs(dirs)\n # add_runtime_library_dir(dir)\n # set_runtime_library_dirs(dirs)\n # add_link_object(object)\n # set_link_objects(objects)\n #\n # detect_language(sources) ### USABLE\n #\n # preprocess(source,output_file=None,macros=None,include_dirs=None,\n # extra_preargs=None,extra_postargs=None)\n # compile(sources, output_dir=None, macros=None,\n # include_dirs=None, debug=0, extra_preargs=None,\n # extra_postargs=None, depends=None)\n # create_static_lib(objects,output_libname,output_dir=None,debug=0,target_lang=None):\n # link(target_desc, objects, output_filename, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None,\n # build_temp=None, target_lang=None)\n # link_shared_lib(objects, output_libname, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None,\n # extra_postargs=None, build_temp=None, target_lang=None)\n # link_shared_object(objects,output_filename,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # export_symbols=None,debug=0,extra_preargs=None,\n # extra_postargs=None,build_temp=None,target_lang=None)\n # link_executable(objects,output_progname,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # debug=0,extra_preargs=None,extra_postargs=None,target_lang=None)\n #\n # library_dir_option(dir)\n # runtime_library_dir_option(dir)\n # library_option(lib)\n # has_function(funcname,includes=None,include_dirs=None,\n # libraries=None,library_dirs=None)\n # find_library_file(dirs, lib, debug=0)\n #\n # object_filenames(source_filenames, strip_dir=0, output_dir='')\n # shared_object_filename(basename, strip_dir=0, output_dir='')\n # executable_filenamee(basename, strip_dir=0, output_dir='')\n # library_filename(libname, lib_type='static',strip_dir=0, output_dir=''):\n #\n # announce(msg, level=1)\n # debug_print(msg)\n # warn(msg)\n # execute(func, args, msg=None, level=1)\n # spawn(cmd)\n # move_file(src,dst)\n # mkpath(name, mode=0777)\n #\n\n language_map = {'.f':'f77',\n '.for':'f77',\n '.F':'f77', # XXX: needs preprocessor\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n '.F90':'f90', # XXX: needs preprocessor\n '.f95':'f90',\n }\n language_order = ['f90','f77']\n\n version_pattern = None\n\n executables = {\n 'version_cmd' : [\"f77\",\"-v\"],\n 'compiler_f77' : [\"f77\"],\n 'compiler_f90' : [\"f90\"],\n 'compiler_fix' : [\"f90\",\"-fixed\"],\n 'linker_so' : [\"f90\",\"-shared\"],\n #'linker_exe' : [\"f90\"], # XXX do we need it??\n 'archiver' : [\"ar\",\"-cr\"],\n 'ranlib' : None,\n }\n\n compile_switch = \"-c\"\n object_switch = \"-o \" # Ending space matters! It will be stripped\n # but if it is missing then object_switch\n # will be prefixed to object file name by\n # string concatenation.\n library_switch = \"-o \" # Ditto!\n\n # Switch to specify where module files are created and searched\n # for USE statement. Normally it is a string and also here ending\n # space matters. See above.\n module_dir_switch = None\n\n # Switch to specify where module files are searched for USE statement.\n module_include_switch = '-I' \n\n pic_flags = [] # Flags to create position-independent code\n\n src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95','.F','.F90']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n static_lib_format = \"lib%s%s\" # or %s%s\n shared_lib_format = \"%s%s\"\n exe_extension = \"\"\n\n ######################################################################\n ## Methods that subclasses may redefine. But don't call these methods!\n ## They are private to FCompiler class and may return unexpected\n ## results if used elsewhere. So, you have been warned..\n\n def get_version_cmd(self):\n \"\"\" Compiler command to print out version information. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n cmd = self.executables['version_cmd']\n if cmd is not None:\n cmd = cmd[0]\n if cmd==f77:\n cmd = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if cmd==f90:\n cmd = self.compiler_f90[0]\n return cmd\n\n def get_linker_so(self):\n \"\"\" Linker command to build shared libraries. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n ln = self.executables['linker_so']\n if ln is not None:\n ln = ln[0]\n if ln==f77:\n ln = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if ln==f90:\n ln = self.compiler_f90[0]\n return ln\n\n def get_flags(self):\n \"\"\" List of flags common to all compiler types. \"\"\"\n return [] + self.pic_flags\n def get_flags_version(self):\n \"\"\" List of compiler flags to print out version information. \"\"\"\n if self.executables['version_cmd']:\n return self.executables['version_cmd'][1:]\n return []\n def get_flags_f77(self):\n \"\"\" List of Fortran 77 specific flags. \"\"\"\n if self.executables['compiler_f77']:\n return self.executables['compiler_f77'][1:]\n return []\n def get_flags_f90(self):\n \"\"\" List of Fortran 90 specific flags. \"\"\"\n if self.executables['compiler_f90']:\n return self.executables['compiler_f90'][1:]\n return []\n def get_flags_fix(self):\n \"\"\" List of Fortran 90 fixed format specific flags. \"\"\"\n if self.executables['compiler_fix']:\n return self.executables['compiler_fix'][1:]\n return []\n def get_flags_linker_so(self):\n \"\"\" List of linker flags to build a shared library. \"\"\"\n if self.executables['linker_so']:\n return self.executables['linker_so'][1:]\n return []\n def get_flags_ar(self):\n \"\"\" List of archiver flags. \"\"\"\n if self.executables['archiver']:\n return self.executables['archiver'][1:]\n return []\n def get_flags_opt(self):\n \"\"\" List of architecture independent compiler flags. \"\"\"\n return []\n def get_flags_arch(self):\n \"\"\" List of architecture dependent compiler flags. \"\"\"\n return []\n def get_flags_debug(self):\n \"\"\" List of compiler flags to compile with debugging information. \"\"\"\n return []\n get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt\n get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch\n get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug\n\n def get_libraries(self):\n \"\"\" List of compiler libraries. \"\"\"\n return self.libraries[:]\n def get_library_dirs(self):\n \"\"\" List of compiler library directories. \"\"\"\n return self.library_dirs[:]\n\n ############################################################\n\n ## Public methods:\n\n def customize(self, dist=None):\n \"\"\" Customize Fortran compiler.\n\n This method gets Fortran compiler specific information from\n (i) class definition, (ii) environment, (iii) distutils config\n files, and (iv) command line.\n\n This method should be always called after constructing a\n compiler instance. But not in __init__ because Distribution\n instance is needed for (iii) and (iv).\n \"\"\"\n log.info('customize %s' % (self.__class__.__name__))\n if dist is None:\n # These hooks are for testing only!\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n conf = dist.get_option_dict('config_fc')\n\n noopt = conf.get('noopt',[None,0])[1]\n noarch = conf.get('noarch',[None,noopt])[1]\n debug = conf.get('debug',[None,0])[1]\n\n f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))\n f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))\n # Temporarily setting f77,f90 compilers so that\n # version_cmd can use their executables.\n if f77:\n self.set_executables(compiler_f77=[f77])\n if f90:\n self.set_executables(compiler_f90=[f90])\n\n # Must set version_cmd before others as self.get_flags*\n # methods may call self.get_version.\n vers_cmd = self.__get_cmd(self.get_version_cmd)\n if vers_cmd:\n vflags = self.__get_flags(self.get_flags_version)\n self.set_executables(version_cmd=[vers_cmd]+vflags)\n\n if f77:\n f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',\n (conf,'f77flags'))\n if f90:\n f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',\n (conf,'f90flags'))\n\n # XXX Assuming that free format is default for f90 compiler.\n fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))\n if fix:\n fixflags = self.__get_flags(self.get_flags_fix) + f90flags\n\n oflags,aflags,dflags = [],[],[]\n if not noopt:\n oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))\n if f77 and self.get_flags_opt is not self.get_flags_opt_f77:\n f77flags += self.__get_flags(self.get_flags_opt_f77)\n if f90 and self.get_flags_opt is not self.get_flags_opt_f90:\n f90flags += self.__get_flags(self.get_flags_opt_f90)\n if fix and self.get_flags_opt is not self.get_flags_opt_f90:\n fixflags += self.__get_flags(self.get_flags_opt_f90)\n if not noarch:\n aflags = self.__get_flags(self.get_flags_arch,'FARCH',\n (conf,'arch'))\n if f77 and self.get_flags_arch is not self.get_flags_arch_f77:\n f77flags += self.__get_flags(self.get_flags_arch_f77)\n if f90 and self.get_flags_arch is not self.get_flags_arch_f90:\n f90flags += self.__get_flags(self.get_flags_arch_f90)\n if fix and self.get_flags_arch is not self.get_flags_arch_f90:\n fixflags += self.__get_flags(self.get_flags_arch_f90)\n if debug:\n dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')\n if f77 and self.get_flags_debug is not self.get_flags_debug_f77:\n f77flags += self.__get_flags(self.get_flags_debug_f77)\n if f90 and self.get_flags_debug is not self.get_flags_debug_f90:\n f90flags += self.__get_flags(self.get_flags_debug_f90)\n if fix and self.get_flags_debug is not self.get_flags_debug_f90:\n fixflags += self.__get_flags(self.get_flags_debug_f90)\n\n fflags = self.__get_flags(self.get_flags,'FFLAGS') \\\n + dflags + oflags + aflags\n\n if f77:\n self.set_executables(compiler_f77=[f77]+f77flags+fflags)\n if f90:\n self.set_executables(compiler_f90=[f90]+f90flags+fflags)\n if fix:\n self.set_executables(compiler_fix=[fix]+fixflags+fflags)\n\n #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS\n linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')\n if linker_so:\n linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')\n self.set_executables(linker_so=[linker_so]+linker_so_flags)\n\n ar = self.__get_cmd('archiver','AR')\n if ar:\n arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')\n self.set_executables(archiver=[ar]+arflags)\n\n ranlib = self.__get_cmd('ranlib','RANLIB')\n if ranlib:\n self.set_executables(ranlib=[ranlib])\n\n self.set_library_dirs(self.get_library_dirs())\n self.set_libraries(self.get_libraries())\n\n verbose = conf.get('verbose',[None,0])[1]\n if verbose:\n self.dump_properties()\n return\n\n def dump_properties(self):\n \"\"\" Print out the attributes of a compiler instance. \"\"\"\n props = []\n for key in self.executables.keys() + \\\n ['version','libraries','library_dirs',\n 'object_switch','compile_switch']:\n if hasattr(self,key):\n v = getattr(self,key)\n props.append((key, None, '= '+`v`))\n props.sort()\n\n pretty_printer = FancyGetopt(props)\n for l in pretty_printer.generate_help(\"%s instance properties:\" \\\n % (self.__class__.__name__)):\n if l[:4]==' --':\n l = ' ' + l[4:]\n print l\n return\n\n ###################\n\n def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):\n \"\"\"Compile 'src' to product 'obj'.\"\"\"\n if is_f_file(src):\n flavor = ':f77'\n compiler = self.compiler_f77\n elif is_free_format(src):\n flavor = ':f90'\n compiler = self.compiler_f90\n if compiler is None:\n raise DistutilsExecError, 'f90 not supported by '\\\n +self.__class__.__name__\n else:\n flavor = ':fix'\n compiler = self.compiler_fix\n if compiler is None:\n raise DistutilsExecError, 'f90 (fixed) not supported by '\\\n +self.__class__.__name__\n if self.object_switch[-1]==' ':\n o_args = [self.object_switch.strip(),obj]\n else:\n o_args = [self.object_switch.strip()+obj]\n\n assert self.compile_switch.strip()\n s_args = [self.compile_switch, src]\n\n if os.name == 'nt':\n compiler = _nt_quote_args(compiler)\n command = compiler + cc_args + s_args + o_args + extra_postargs\n\n display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,\n src)\n try:\n self.spawn(command,display=display)\n except DistutilsExecError, msg:\n raise CompileError, msg\n\n return\n\n def module_options(self, module_dirs, module_build_dir):\n options = []\n if self.module_dir_switch is not None:\n if self.module_dir_switch[-1]==' ':\n options.extend([self.module_dir_switch.strip(),module_build_dir])\n else:\n options.append(self.module_dir_switch.strip()+module_build_dir)\n else:\n print 'XXX: module_build_dir=%r option ignored' % (module_build_dir)\n print 'XXX: Fix module_dir_switch for ',self.__class__.__name__\n if self.module_include_switch is not None:\n for d in [module_build_dir]+module_dirs:\n options.append('%s%s' % (self.module_include_switch, d))\n else:\n print 'XXX: module_dirs=%r option ignored' % (module_dirs)\n print 'XXX: Fix module_include_switch for ',self.__class__.__name__\n return options\n\n def library_option(self, lib):\n return \"-l\" + lib\n def library_dir_option(self, dir):\n return \"-L\" + dir\n\n# def _get_cc_args(self, pp_opts, debug, extra_preargs):\n# return []\n\n if sys.version[:3]<'2.3':\n def compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if output_dir is None: output_dir = self.output_dir\n if macros is None: macros = self.macros\n elif type(macros) is ListType: macros = macros + (self.macros or [])\n if include_dirs is None: include_dirs = self.include_dirs\n elif type(include_dirs) in (ListType, TupleType):\n include_dirs = list(include_dirs) + (self.include_dirs or [])\n if extra_preargs is None: extra_preargs=[]\n from distutils.sysconfig import python_build\n objects = self.object_filenames(sources,strip_dir=python_build,\n output_dir=output_dir)\n from distutils.ccompiler import gen_preprocess_options\n pp_opts = gen_preprocess_options(macros, include_dirs)\n build = {}\n for i in range(len(sources)):\n src,obj = sources[i],objects[i]\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n def detect_language(self, sources):\n return\n\n def link(self, target_desc, objects,\n output_filename, output_dir=None, libraries=None,\n library_dirs=None, runtime_library_dirs=None,\n export_symbols=None, debug=0, extra_preargs=None,\n extra_postargs=None, build_temp=None, target_lang=None):\n objects, output_dir = self._fix_object_args(objects, output_dir)\n libraries, library_dirs, runtime_library_dirs = \\\n self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)\n\n lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,\n libraries)\n if type(output_dir) not in (StringType, NoneType):\n raise TypeError, \"'output_dir' must be a string or None\"\n if output_dir is not None:\n output_filename = os.path.join(output_dir, output_filename)\n\n if self._need_link(objects, output_filename):\n if self.library_switch[-1]==' ':\n o_args = [self.library_switch.strip(),output_filename]\n else:\n o_args = [self.library_switch.strip()+output_filename]\n ld_args = (objects + self.objects +\n lib_opts + o_args)\n if debug:\n ld_args[:0] = ['-g']\n if extra_preargs:\n ld_args[:0] = extra_preargs\n if extra_postargs:\n ld_args.extend(extra_postargs)\n self.mkpath(os.path.dirname(output_filename))\n if target_desc == CCompiler.EXECUTABLE:\n raise NotImplementedError,self.__class__.__name__+'.linker_exe attribute'\n else:\n linker = self.linker_so[:]\n if os.name == 'nt':\n linker = _nt_quote_args(linker)\n command = linker + ld_args\n try:\n self.spawn(command)\n except DistutilsExecError, msg:\n raise LinkError, msg\n else:\n log.debug(\"skipping %s (up-to-date)\", output_filename)\n return\n\n ############################################################\n\n ## Private methods:\n\n def __get_cmd(self, command, envvar=None, confvar=None):\n if command is None:\n var = None\n elif type(command) is type(''):\n var = self.executables[command]\n if var is not None:\n var = var[0]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n return var\n\n def __get_flags(self, command, envvar=None, confvar=None):\n if command is None:\n var = []\n elif type(command) is type(''):\n var = self.executables[command][1:]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n if type(var) is type(''):\n var = split_quoted(var)\n return var\n\n ## class FCompiler\n\n##############################################################################\n\nfcompiler_class = {'gnu':('gnufcompiler','GnuFCompiler',\n \"GNU Fortran Compiler\"),\n 'pg':('pgfcompiler','PGroupFCompiler',\n \"Portland Group Fortran Compiler\"),\n 'absoft':('absoftfcompiler','AbsoftFCompiler',\n \"Absoft Corp Fortran Compiler\"),\n 'mips':('mipsfcompiler','MipsFCompiler',\n \"MIPSpro Fortran Compiler\"),\n 'sun':('sunfcompiler','SunFCompiler',\n \"Sun|Forte Fortran 95 Compiler\"),\n 'intel':('intelfcompiler','IntelFCompiler',\n \"Intel Fortran Compiler for 32-bit apps\"),\n 'intelv':('intelfcompiler','IntelVisualFCompiler',\n \"Intel Visual Fortran Compiler for 32-bit apps\"),\n 'intele':('intelfcompiler','IntelItaniumFCompiler',\n \"Intel Fortran Compiler for Itanium apps\"),\n 'intelev':('intelfcompiler','IntelItaniumVisualFCompiler',\n \"Intel Visual Fortran Compiler for Itanium apps\"),\n 'nag':('nagfcompiler','NAGFCompiler',\n \"NAGWare Fortran 95 Compiler\"),\n 'compaq':('compaqfcompiler','CompaqFCompiler',\n \"Compaq Fortran Compiler\"),\n 'compaqv':('compaqfcompiler','CompaqVisualFCompiler',\n \"DIGITAL|Compaq Visual Fortran Compiler\"),\n 'vast':('vastfcompiler','VastFCompiler',\n \"Pacific-Sierra Research Fortran 90 Compiler\"),\n 'hpux':('hpuxfcompiler','HPUXFCompiler',\n \"HP Fortran 90 Compiler\"),\n 'lahey':('laheyfcompiler','LaheyFCompiler',\n \"Lahey/Fujitsu Fortran 95 Compiler\"),\n 'ibm':('ibmfcompiler','IbmFCompiler',\n \"IBM XL Fortran Compiler\"),\n 'f':('fcompiler','FFCompiler',\n \"Fortran Company/NAG F Compiler\"),\n }\n\n_default_compilers = (\n # Platform mappings\n ('win32',('gnu','intelv','absoft','compaqv','intelev')),\n ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev')),\n ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',\n 'intele')),\n ('darwin.*',('nag','absoft','ibm','gnu')),\n ('sunos.*',('forte','gnu','sun')),\n ('irix.*',('mips','gnu')),\n ('aix.*',('ibm','gnu')),\n # OS mappings\n ('posix',('gnu',)),\n ('nt',('gnu',)),\n ('mac',('gnu',)),\n )\n\ndef _find_existing_fcompiler(compilers, osname=None, platform=None):\n for compiler in compilers:\n v = None\n try:\n c = new_fcompiler(plat=platform, compiler=compiler)\n c.customize()\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is not None:\n return compiler\n return\n\ndef get_default_fcompiler(osname=None, platform=None):\n \"\"\" Determine the default Fortran compiler to use for the given platform. \"\"\"\n if osname is None:\n osname = os.name\n if platform is None:\n platform = sys.platform\n matching_compilers = []\n for pattern, compiler in _default_compilers:\n if re.match(pattern, platform) is not None or \\\n re.match(pattern, osname) is not None:\n if type(compiler) is type(()):\n matching_compilers.extend(list(compiler))\n else:\n matching_compilers.append(compiler)\n if not matching_compilers:\n matching_compilers.append('gnu')\n compiler = _find_existing_fcompiler(matching_compilers,\n osname=osname,\n platform=platform)\n if compiler is not None:\n return compiler\n return matching_compilers[0]\n\ndef new_fcompiler(plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n \"\"\" Generate an instance of some FCompiler subclass for the supplied\n platform/compiler combination.\n \"\"\"\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_fcompiler(plat)\n (module_name, class_name, long_description) = fcompiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile Fortran code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler.\" % compiler\n msg = msg + \" Supported compilers are: %s)\" \\\n % (','.join(fcompiler_class.keys()))\n raise DistutilsPlatformError, msg\n\n try:\n module_name = 'scipy_distutils.'+module_name\n __import__ (module_name)\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile Fortran code: unable to load module '%s'\" % \\\n module_name\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile Fortran code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\ndef show_fcompilers(dist = None):\n \"\"\" Print list of available compilers (used by the \"--help-fcompiler\"\n option to \"config_fc\").\n \"\"\"\n if dist is None:\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n compilers = []\n compilers_na = []\n compilers_ni = []\n for compiler in fcompiler_class.keys():\n v = 'N/A'\n try:\n c = new_fcompiler(compiler=compiler)\n c.customize(dist)\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is None:\n compilers_na.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n elif v=='N/A':\n compilers_ni.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n else:\n compilers.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2] + ' (%s)' % v))\n compilers.sort()\n compilers_na.sort()\n pretty_printer = FancyGetopt(compilers)\n pretty_printer.print_help(\"List of available Fortran compilers:\")\n pretty_printer = FancyGetopt(compilers_na)\n pretty_printer.print_help(\"List of unavailable Fortran compilers:\")\n if compilers_ni:\n pretty_printer = FancyGetopt(compilers_ni)\n pretty_printer.print_help(\"List of unimplemented Fortran compilers:\")\n print \"For compiler details, run 'config_fc --verbose' setup command.\"\n\ndef dummy_fortran_file():\n import tempfile\n dummy_name = tempfile.mktemp()+'__dummy'\n dummy = open(dummy_name+'.f','w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n save_th = log._global_log.threshold\n log.set_threshold(log_threshold)\n try: os.remove(name+'.f'); log.debug('removed '+name+'.f')\n except OSError: pass\n try: os.remove(name+'.o'); log.debug('removed '+name+'.o')\n except OSError: pass\n log.set_threshold(save_th)\n atexit.register(rm_file)\n return dummy_name\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\nif __name__ == '__main__':\n show_fcompilers()\n", "source_code_before": "\"\"\"scipy_distutils.fcompiler\n\nContains FCompiler, an abstract base class that defines the interface\nfor the Scipy_distutils Fortran compiler abstraction model.\n\n\"\"\"\n\nimport re\nimport os\nimport sys\nimport atexit\nfrom types import StringType, NoneType, ListType, TupleType\nfrom glob import glob\n\nfrom distutils.version import StrictVersion\nfrom scipy_distutils.ccompiler import CCompiler, gen_lib_options\n# distutils.ccompiler provides the following functions:\n# gen_preprocess_options(macros, include_dirs)\n# gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)\nfrom distutils.errors import DistutilsModuleError,DistutilsArgError,\\\n DistutilsExecError,CompileError,LinkError,DistutilsPlatformError\nfrom distutils.core import Command\nfrom distutils.util import split_quoted\nfrom distutils.fancy_getopt import FancyGetopt\nfrom distutils.sysconfig import get_config_var\nfrom distutils.spawn import _nt_quote_args \n\n\nfrom scipy_distutils.command.config_compiler import config_fc\n\nimport log\nfrom misc_util import compiler_to_string\nfrom exec_command import find_executable, exec_command\n\nclass FCompiler(CCompiler):\n \"\"\" Abstract base class to define the interface that must be implemented\n by real Fortran compiler classes.\n\n Methods that subclasses may redefine:\n\n get_version_cmd(), get_linker_so(), get_version()\n get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()\n get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),\n get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),\n get_flags_arch_f90(), get_flags_debug_f90(),\n get_flags_fix(), get_flags_linker_so(), get_flags_version()\n\n DON'T call these methods (except get_version) after\n constructing a compiler instance or inside any other method.\n All methods, except get_version_cmd() and get_flags_version(), may\n call get_version() method.\n\n After constructing a compiler instance, always call customize(dist=None)\n method that finalizes compiler construction and makes the following\n attributes available:\n compiler_f77\n compiler_f90\n compiler_fix\n linker_so\n archiver\n ranlib\n libraries\n library_dirs\n \"\"\"\n # CCompiler defines the following attributes:\n # compiler_type\n # src_extensions\n # obj_extension\n # static_lib_extension\n # shared_lib_extension\n # static_lib_format\n # shared_lib_format\n # exe_extension\n # language_map ### REDEFINED\n # language_order ### REDEFINED\n # and the following public methods:\n # set_executables(**args)\n # set_executable(key,value)\n # define_macro(name, value=None)\n # undefine_macro(name)\n # add_include_dir(dir)\n # set_include_dirs(dirs)\n # add_library(libname)\n # set_libraries(libnames)\n # add_library_dir(dir)\n # set_library_dirs(dirs)\n # add_runtime_library_dir(dir)\n # set_runtime_library_dirs(dirs)\n # add_link_object(object)\n # set_link_objects(objects)\n #\n # detect_language(sources) ### USABLE\n #\n # preprocess(source,output_file=None,macros=None,include_dirs=None,\n # extra_preargs=None,extra_postargs=None)\n # compile(sources, output_dir=None, macros=None,\n # include_dirs=None, debug=0, extra_preargs=None,\n # extra_postargs=None, depends=None)\n # create_static_lib(objects,output_libname,output_dir=None,debug=0,target_lang=None):\n # link(target_desc, objects, output_filename, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None,\n # build_temp=None, target_lang=None)\n # link_shared_lib(objects, output_libname, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None,\n # extra_postargs=None, build_temp=None, target_lang=None)\n # link_shared_object(objects,output_filename,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # export_symbols=None,debug=0,extra_preargs=None,\n # extra_postargs=None,build_temp=None,target_lang=None)\n # link_executable(objects,output_progname,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # debug=0,extra_preargs=None,extra_postargs=None,target_lang=None)\n #\n # library_dir_option(dir)\n # runtime_library_dir_option(dir)\n # library_option(lib)\n # has_function(funcname,includes=None,include_dirs=None,\n # libraries=None,library_dirs=None)\n # find_library_file(dirs, lib, debug=0)\n #\n # object_filenames(source_filenames, strip_dir=0, output_dir='')\n # shared_object_filename(basename, strip_dir=0, output_dir='')\n # executable_filenamee(basename, strip_dir=0, output_dir='')\n # library_filename(libname, lib_type='static',strip_dir=0, output_dir=''):\n #\n # announce(msg, level=1)\n # debug_print(msg)\n # warn(msg)\n # execute(func, args, msg=None, level=1)\n # spawn(cmd)\n # move_file(src,dst)\n # mkpath(name, mode=0777)\n #\n\n language_map = {'.f':'f77',\n '.for':'f77',\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n '.f95':'f90'}\n language_order = ['f90','f77']\n\n version_pattern = None\n\n executables = {\n 'version_cmd' : [\"f77\",\"-v\"],\n 'compiler_f77' : [\"f77\"],\n 'compiler_f90' : [\"f90\"],\n 'compiler_fix' : [\"f90\",\"-fixed\"],\n 'linker_so' : [\"f90\",\"-shared\"],\n #'linker_exe' : [\"f90\"], # XXX do we need it??\n 'archiver' : [\"ar\",\"-cr\"],\n 'ranlib' : None,\n }\n\n compile_switch = \"-c\"\n object_switch = \"-o \" # Ending space matters! It will be stripped\n # but if it is missing then object_switch\n # will be prefixed to object file name by\n # string concatenation.\n library_switch = \"-o \" # Ditto!\n\n # Switch to specify where module files are created and searched\n # for USE statement. Normally it is a string and also here ending\n # space matters. See above.\n module_dir_switch = None\n\n # Switch to specify where module files are searched for USE statement.\n module_include_switch = '-I' \n\n pic_flags = [] # Flags to create position-independent code\n\n src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n static_lib_format = \"lib%s%s\" # or %s%s\n shared_lib_format = \"%s%s\"\n exe_extension = \"\"\n\n ######################################################################\n ## Methods that subclasses may redefine. But don't call these methods!\n ## They are private to FCompiler class and may return unexpected\n ## results if used elsewhere. So, you have been warned..\n\n def get_version_cmd(self):\n \"\"\" Compiler command to print out version information. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n cmd = self.executables['version_cmd']\n if cmd is not None:\n cmd = cmd[0]\n if cmd==f77:\n cmd = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if cmd==f90:\n cmd = self.compiler_f90[0]\n return cmd\n\n def get_linker_so(self):\n \"\"\" Linker command to build shared libraries. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n ln = self.executables['linker_so']\n if ln is not None:\n ln = ln[0]\n if ln==f77:\n ln = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if ln==f90:\n ln = self.compiler_f90[0]\n return ln\n\n def get_flags(self):\n \"\"\" List of flags common to all compiler types. \"\"\"\n return [] + self.pic_flags\n def get_flags_version(self):\n \"\"\" List of compiler flags to print out version information. \"\"\"\n if self.executables['version_cmd']:\n return self.executables['version_cmd'][1:]\n return []\n def get_flags_f77(self):\n \"\"\" List of Fortran 77 specific flags. \"\"\"\n if self.executables['compiler_f77']:\n return self.executables['compiler_f77'][1:]\n return []\n def get_flags_f90(self):\n \"\"\" List of Fortran 90 specific flags. \"\"\"\n if self.executables['compiler_f90']:\n return self.executables['compiler_f90'][1:]\n return []\n def get_flags_fix(self):\n \"\"\" List of Fortran 90 fixed format specific flags. \"\"\"\n if self.executables['compiler_fix']:\n return self.executables['compiler_fix'][1:]\n return []\n def get_flags_linker_so(self):\n \"\"\" List of linker flags to build a shared library. \"\"\"\n if self.executables['linker_so']:\n return self.executables['linker_so'][1:]\n return []\n def get_flags_ar(self):\n \"\"\" List of archiver flags. \"\"\"\n if self.executables['archiver']:\n return self.executables['archiver'][1:]\n return []\n def get_flags_opt(self):\n \"\"\" List of architecture independent compiler flags. \"\"\"\n return []\n def get_flags_arch(self):\n \"\"\" List of architecture dependent compiler flags. \"\"\"\n return []\n def get_flags_debug(self):\n \"\"\" List of compiler flags to compile with debugging information. \"\"\"\n return []\n get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt\n get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch\n get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug\n\n def get_libraries(self):\n \"\"\" List of compiler libraries. \"\"\"\n return self.libraries[:]\n def get_library_dirs(self):\n \"\"\" List of compiler library directories. \"\"\"\n return self.library_dirs[:]\n\n ############################################################\n\n ## Public methods:\n\n def customize(self, dist=None):\n \"\"\" Customize Fortran compiler.\n\n This method gets Fortran compiler specific information from\n (i) class definition, (ii) environment, (iii) distutils config\n files, and (iv) command line.\n\n This method should be always called after constructing a\n compiler instance. But not in __init__ because Distribution\n instance is needed for (iii) and (iv).\n \"\"\"\n log.info('customize %s' % (self.__class__.__name__))\n if dist is None:\n # These hooks are for testing only!\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n conf = dist.get_option_dict('config_fc')\n\n noopt = conf.get('noopt',[None,0])[1]\n noarch = conf.get('noarch',[None,noopt])[1]\n debug = conf.get('debug',[None,0])[1]\n\n f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))\n f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))\n # Temporarily setting f77,f90 compilers so that\n # version_cmd can use their executables.\n if f77:\n self.set_executables(compiler_f77=[f77])\n if f90:\n self.set_executables(compiler_f90=[f90])\n\n # Must set version_cmd before others as self.get_flags*\n # methods may call self.get_version.\n vers_cmd = self.__get_cmd(self.get_version_cmd)\n if vers_cmd:\n vflags = self.__get_flags(self.get_flags_version)\n self.set_executables(version_cmd=[vers_cmd]+vflags)\n\n if f77:\n f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',\n (conf,'f77flags'))\n if f90:\n f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',\n (conf,'f90flags'))\n\n # XXX Assuming that free format is default for f90 compiler.\n fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))\n if fix:\n fixflags = self.__get_flags(self.get_flags_fix) + f90flags\n\n oflags,aflags,dflags = [],[],[]\n if not noopt:\n oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))\n if f77 and self.get_flags_opt is not self.get_flags_opt_f77:\n f77flags += self.__get_flags(self.get_flags_opt_f77)\n if f90 and self.get_flags_opt is not self.get_flags_opt_f90:\n f90flags += self.__get_flags(self.get_flags_opt_f90)\n if fix and self.get_flags_opt is not self.get_flags_opt_f90:\n fixflags += self.__get_flags(self.get_flags_opt_f90)\n if not noarch:\n aflags = self.__get_flags(self.get_flags_arch,'FARCH',\n (conf,'arch'))\n if f77 and self.get_flags_arch is not self.get_flags_arch_f77:\n f77flags += self.__get_flags(self.get_flags_arch_f77)\n if f90 and self.get_flags_arch is not self.get_flags_arch_f90:\n f90flags += self.__get_flags(self.get_flags_arch_f90)\n if fix and self.get_flags_arch is not self.get_flags_arch_f90:\n fixflags += self.__get_flags(self.get_flags_arch_f90)\n if debug:\n dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')\n if f77 and self.get_flags_debug is not self.get_flags_debug_f77:\n f77flags += self.__get_flags(self.get_flags_debug_f77)\n if f90 and self.get_flags_debug is not self.get_flags_debug_f90:\n f90flags += self.__get_flags(self.get_flags_debug_f90)\n if fix and self.get_flags_debug is not self.get_flags_debug_f90:\n fixflags += self.__get_flags(self.get_flags_debug_f90)\n\n fflags = self.__get_flags(self.get_flags,'FFLAGS') \\\n + dflags + oflags + aflags\n\n if f77:\n self.set_executables(compiler_f77=[f77]+f77flags+fflags)\n if f90:\n self.set_executables(compiler_f90=[f90]+f90flags+fflags)\n if fix:\n self.set_executables(compiler_fix=[fix]+fixflags+fflags)\n\n #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS\n linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')\n if linker_so:\n linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')\n self.set_executables(linker_so=[linker_so]+linker_so_flags)\n\n ar = self.__get_cmd('archiver','AR')\n if ar:\n arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')\n self.set_executables(archiver=[ar]+arflags)\n\n ranlib = self.__get_cmd('ranlib','RANLIB')\n if ranlib:\n self.set_executables(ranlib=[ranlib])\n\n self.set_library_dirs(self.get_library_dirs())\n self.set_libraries(self.get_libraries())\n\n verbose = conf.get('verbose',[None,0])[1]\n if verbose:\n self.dump_properties()\n return\n\n def dump_properties(self):\n \"\"\" Print out the attributes of a compiler instance. \"\"\"\n props = []\n for key in self.executables.keys() + \\\n ['version','libraries','library_dirs',\n 'object_switch','compile_switch']:\n if hasattr(self,key):\n v = getattr(self,key)\n props.append((key, None, '= '+`v`))\n props.sort()\n\n pretty_printer = FancyGetopt(props)\n for l in pretty_printer.generate_help(\"%s instance properties:\" \\\n % (self.__class__.__name__)):\n if l[:4]==' --':\n l = ' ' + l[4:]\n print l\n return\n\n ###################\n\n def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):\n \"\"\"Compile 'src' to product 'obj'.\"\"\"\n if is_f_file(src):\n flavor = ':f77'\n compiler = self.compiler_f77\n elif is_free_format(src):\n flavor = ':f90'\n compiler = self.compiler_f90\n if compiler is None:\n raise DistutilsExecError, 'f90 not supported by '\\\n +self.__class__.__name__\n else:\n flavor = ':fix'\n compiler = self.compiler_fix\n if compiler is None:\n raise DistutilsExecError, 'f90 (fixed) not supported by '\\\n +self.__class__.__name__\n if self.object_switch[-1]==' ':\n o_args = [self.object_switch.strip(),obj]\n else:\n o_args = [self.object_switch.strip()+obj]\n\n assert self.compile_switch.strip()\n s_args = [self.compile_switch, src]\n\n if os.name == 'nt':\n compiler = _nt_quote_args(compiler)\n command = compiler + cc_args + s_args + o_args + extra_postargs\n\n display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,\n src)\n try:\n self.spawn(command,display=display)\n except DistutilsExecError, msg:\n raise CompileError, msg\n\n return\n\n def module_options(self, module_dirs, module_build_dir):\n options = []\n if self.module_dir_switch is not None:\n if self.module_dir_switch[-1]==' ':\n options.extend([self.module_dir_switch.strip(),module_build_dir])\n else:\n options.append(self.module_dir_switch.strip()+module_build_dir)\n else:\n print 'XXX: module_build_dir=%r option ignored' % (module_build_dir)\n print 'XXX: Fix module_dir_switch for ',self.__class__.__name__\n if self.module_include_switch is not None:\n for d in [module_build_dir]+module_dirs:\n options.append('%s%s' % (self.module_include_switch, d))\n else:\n print 'XXX: module_dirs=%r option ignored' % (module_dirs)\n print 'XXX: Fix module_include_switch for ',self.__class__.__name__\n return options\n\n def library_option(self, lib):\n return \"-l\" + lib\n def library_dir_option(self, dir):\n return \"-L\" + dir\n\n# def _get_cc_args(self, pp_opts, debug, extra_preargs):\n# return []\n\n if sys.version[:3]<'2.3':\n def compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if output_dir is None: output_dir = self.output_dir\n if macros is None: macros = self.macros\n elif type(macros) is ListType: macros = macros + (self.macros or [])\n if include_dirs is None: include_dirs = self.include_dirs\n elif type(include_dirs) in (ListType, TupleType):\n include_dirs = list(include_dirs) + (self.include_dirs or [])\n if extra_preargs is None: extra_preargs=[]\n from distutils.sysconfig import python_build\n objects = self.object_filenames(sources,strip_dir=python_build,\n output_dir=output_dir)\n from distutils.ccompiler import gen_preprocess_options\n pp_opts = gen_preprocess_options(macros, include_dirs)\n build = {}\n for i in range(len(sources)):\n src,obj = sources[i],objects[i]\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n def detect_language(self, sources):\n return\n\n def link(self, target_desc, objects,\n output_filename, output_dir=None, libraries=None,\n library_dirs=None, runtime_library_dirs=None,\n export_symbols=None, debug=0, extra_preargs=None,\n extra_postargs=None, build_temp=None, target_lang=None):\n objects, output_dir = self._fix_object_args(objects, output_dir)\n libraries, library_dirs, runtime_library_dirs = \\\n self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)\n\n lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,\n libraries)\n if type(output_dir) not in (StringType, NoneType):\n raise TypeError, \"'output_dir' must be a string or None\"\n if output_dir is not None:\n output_filename = os.path.join(output_dir, output_filename)\n\n if self._need_link(objects, output_filename):\n if self.library_switch[-1]==' ':\n o_args = [self.library_switch.strip(),output_filename]\n else:\n o_args = [self.library_switch.strip()+output_filename]\n ld_args = (objects + self.objects +\n lib_opts + o_args)\n if debug:\n ld_args[:0] = ['-g']\n if extra_preargs:\n ld_args[:0] = extra_preargs\n if extra_postargs:\n ld_args.extend(extra_postargs)\n self.mkpath(os.path.dirname(output_filename))\n if target_desc == CCompiler.EXECUTABLE:\n raise NotImplementedError,self.__class__.__name__+'.linker_exe attribute'\n else:\n linker = self.linker_so[:]\n if os.name == 'nt':\n linker = _nt_quote_args(linker)\n command = linker + ld_args\n try:\n self.spawn(command)\n except DistutilsExecError, msg:\n raise LinkError, msg\n else:\n log.debug(\"skipping %s (up-to-date)\", output_filename)\n return\n\n ############################################################\n\n ## Private methods:\n\n def __get_cmd(self, command, envvar=None, confvar=None):\n if command is None:\n var = None\n elif type(command) is type(''):\n var = self.executables[command]\n if var is not None:\n var = var[0]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n return var\n\n def __get_flags(self, command, envvar=None, confvar=None):\n if command is None:\n var = []\n elif type(command) is type(''):\n var = self.executables[command][1:]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n if type(var) is type(''):\n var = split_quoted(var)\n return var\n\n ## class FCompiler\n\n##############################################################################\n\nfcompiler_class = {'gnu':('gnufcompiler','GnuFCompiler',\n \"GNU Fortran Compiler\"),\n 'pg':('pgfcompiler','PGroupFCompiler',\n \"Portland Group Fortran Compiler\"),\n 'absoft':('absoftfcompiler','AbsoftFCompiler',\n \"Absoft Corp Fortran Compiler\"),\n 'mips':('mipsfcompiler','MipsFCompiler',\n \"MIPSpro Fortran Compiler\"),\n 'sun':('sunfcompiler','SunFCompiler',\n \"Sun|Forte Fortran 95 Compiler\"),\n 'intel':('intelfcompiler','IntelFCompiler',\n \"Intel Fortran Compiler for 32-bit apps\"),\n 'intelv':('intelfcompiler','IntelVisualFCompiler',\n \"Intel Visual Fortran Compiler for 32-bit apps\"),\n 'intele':('intelfcompiler','IntelItaniumFCompiler',\n \"Intel Fortran Compiler for Itanium apps\"),\n 'intelev':('intelfcompiler','IntelItaniumVisualFCompiler',\n \"Intel Visual Fortran Compiler for Itanium apps\"),\n 'nag':('nagfcompiler','NAGFCompiler',\n \"NAGWare Fortran 95 Compiler\"),\n 'compaq':('compaqfcompiler','CompaqFCompiler',\n \"Compaq Fortran Compiler\"),\n 'compaqv':('compaqfcompiler','CompaqVisualFCompiler',\n \"DIGITAL|Compaq Visual Fortran Compiler\"),\n 'vast':('vastfcompiler','VastFCompiler',\n \"Pacific-Sierra Research Fortran 90 Compiler\"),\n 'hpux':('hpuxfcompiler','HPUXFCompiler',\n \"HP Fortran 90 Compiler\"),\n 'lahey':('laheyfcompiler','LaheyFCompiler',\n \"Lahey/Fujitsu Fortran 95 Compiler\"),\n 'ibm':('ibmfcompiler','IbmFCompiler',\n \"IBM XL Fortran Compiler\"),\n 'f':('fcompiler','FFCompiler',\n \"Fortran Company/NAG F Compiler\"),\n }\n\n_default_compilers = (\n # Platform mappings\n ('win32',('gnu','intelv','absoft','compaqv','intelev')),\n ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev')),\n ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',\n 'intele')),\n ('darwin.*',('nag','absoft','ibm','gnu')),\n ('sunos.*',('forte','gnu','sun')),\n ('irix.*',('mips','gnu')),\n ('aix.*',('ibm','gnu')),\n # OS mappings\n ('posix',('gnu',)),\n ('nt',('gnu',)),\n ('mac',('gnu',)),\n )\n\ndef _find_existing_fcompiler(compilers, osname=None, platform=None):\n for compiler in compilers:\n v = None\n try:\n c = new_fcompiler(plat=platform, compiler=compiler)\n c.customize()\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is not None:\n return compiler\n return\n\ndef get_default_fcompiler(osname=None, platform=None):\n \"\"\" Determine the default Fortran compiler to use for the given platform. \"\"\"\n if osname is None:\n osname = os.name\n if platform is None:\n platform = sys.platform\n matching_compilers = []\n for pattern, compiler in _default_compilers:\n if re.match(pattern, platform) is not None or \\\n re.match(pattern, osname) is not None:\n if type(compiler) is type(()):\n matching_compilers.extend(list(compiler))\n else:\n matching_compilers.append(compiler)\n if not matching_compilers:\n matching_compilers.append('gnu')\n compiler = _find_existing_fcompiler(matching_compilers,\n osname=osname,\n platform=platform)\n if compiler is not None:\n return compiler\n return matching_compilers[0]\n\ndef new_fcompiler(plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n \"\"\" Generate an instance of some FCompiler subclass for the supplied\n platform/compiler combination.\n \"\"\"\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_fcompiler(plat)\n (module_name, class_name, long_description) = fcompiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile Fortran code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler.\" % compiler\n msg = msg + \" Supported compilers are: %s)\" \\\n % (','.join(fcompiler_class.keys()))\n raise DistutilsPlatformError, msg\n\n try:\n module_name = 'scipy_distutils.'+module_name\n __import__ (module_name)\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile Fortran code: unable to load module '%s'\" % \\\n module_name\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile Fortran code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\ndef show_fcompilers(dist = None):\n \"\"\" Print list of available compilers (used by the \"--help-fcompiler\"\n option to \"config_fc\").\n \"\"\"\n if dist is None:\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n compilers = []\n compilers_na = []\n compilers_ni = []\n for compiler in fcompiler_class.keys():\n v = 'N/A'\n try:\n c = new_fcompiler(compiler=compiler)\n c.customize(dist)\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is None:\n compilers_na.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n elif v=='N/A':\n compilers_ni.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n else:\n compilers.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2] + ' (%s)' % v))\n compilers.sort()\n compilers_na.sort()\n pretty_printer = FancyGetopt(compilers)\n pretty_printer.print_help(\"List of available Fortran compilers:\")\n pretty_printer = FancyGetopt(compilers_na)\n pretty_printer.print_help(\"List of unavailable Fortran compilers:\")\n if compilers_ni:\n pretty_printer = FancyGetopt(compilers_ni)\n pretty_printer.print_help(\"List of unimplemented Fortran compilers:\")\n print \"For compiler details, run 'config_fc --verbose' setup command.\"\n\ndef dummy_fortran_file():\n import tempfile\n dummy_name = tempfile.mktemp()+'__dummy'\n dummy = open(dummy_name+'.f','w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n save_th = log._global_log.threshold\n log.set_threshold(log_threshold)\n try: os.remove(name+'.f'); log.debug('removed '+name+'.f')\n except OSError: pass\n try: os.remove(name+'.o'); log.debug('removed '+name+'.o')\n except OSError: pass\n log.set_threshold(save_th)\n atexit.register(rm_file)\n return dummy_name\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\nif __name__ == '__main__':\n show_fcompilers()\n", "methods": [ { "name": "get_version_cmd", "long_name": "get_version_cmd( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 191, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 209, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 227, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_version", "long_name": "get_flags_version( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 230, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 235, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 240, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 245, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 250, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_ar", "long_name": "get_flags_ar( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 255, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 260, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 266, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 273, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 276, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "customize", "long_name": "customize( self , dist = None )", "filename": "fcompiler.py", "nloc": 84, "complexity": 36, "token_count": 799, "parameters": [ "self", "dist" ], "start_line": 284, "end_line": 398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 115, "top_nesting_level": 1 }, { "name": "dump_properties", "long_name": "dump_properties( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 5, "token_count": 117, "parameters": [ "self" ], "start_line": 400, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "_compile", "long_name": "_compile( self , obj , src , ext , cc_args , extra_postargs , pp_opts )", "filename": "fcompiler.py", "nloc": 32, "complexity": 8, "token_count": 211, "parameters": [ "self", "obj", "src", "ext", "cc_args", "extra_postargs", "pp_opts" ], "start_line": 421, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "module_options", "long_name": "module_options( self , module_dirs , module_build_dir )", "filename": "fcompiler.py", "nloc": 17, "complexity": 5, "token_count": 129, "parameters": [ "self", "module_dirs", "module_build_dir" ], "start_line": 459, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "library_option", "long_name": "library_option( self , lib )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "lib" ], "start_line": 477, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "library_dir_option", "long_name": "library_dir_option( self , dir )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "dir" ], "start_line": 479, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 256, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 486, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 }, { "name": "detect_language", "long_name": "detect_language( self , sources )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self", "sources" ], "start_line": 511, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir = None , libraries = None , library_dirs = None , runtime_library_dirs = None , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "fcompiler.py", "nloc": 42, "complexity": 11, "token_count": 306, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 514, "end_line": 557, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 1 }, { "name": "__get_cmd", "long_name": "__get_cmd( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 110, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 563, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__get_flags", "long_name": "__get_flags( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 120, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 578, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "_find_existing_fcompiler", "long_name": "_find_existing_fcompiler( compilers , osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 5, "token_count": 71, "parameters": [ "compilers", "osname", "platform" ], "start_line": 649, "end_line": 662, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_default_fcompiler", "long_name": "get_default_fcompiler( osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 21, "complexity": 9, "token_count": 135, "parameters": [ "osname", "platform" ], "start_line": 664, "end_line": 685, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "new_fcompiler", "long_name": "new_fcompiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "fcompiler.py", "nloc": 34, "complexity": 7, "token_count": 182, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 687, "end_line": 724, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "show_fcompilers", "long_name": "show_fcompilers( dist = None )", "filename": "fcompiler.py", "nloc": 41, "complexity": 8, "token_count": 261, "parameters": [ "dist" ], "start_line": 726, "end_line": 770, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "dummy_fortran_file.rm_file", "long_name": "dummy_fortran_file.rm_file( name = dummy_name , log_threshold = log . _global_log . threshold )", "filename": "fcompiler.py", "nloc": 8, "complexity": 3, "token_count": 84, "parameters": [ "name", "log_threshold" ], "start_line": 778, "end_line": 785, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "dummy_fortran_file", "long_name": "dummy_fortran_file( )", "filename": "fcompiler.py", "nloc": 9, "complexity": 1, "token_count": 46, "parameters": [], "start_line": 772, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "is_free_format", "long_name": "is_free_format( file )", "filename": "fcompiler.py", "nloc": 19, "complexity": 9, "token_count": 114, "parameters": [ "file" ], "start_line": 793, "end_line": 814, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_version_cmd", "long_name": "get_version_cmd( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 188, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 206, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 224, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_version", "long_name": "get_flags_version( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 227, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_ar", "long_name": "get_flags_ar( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 257, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 260, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 270, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 273, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "customize", "long_name": "customize( self , dist = None )", "filename": "fcompiler.py", "nloc": 84, "complexity": 36, "token_count": 799, "parameters": [ "self", "dist" ], "start_line": 281, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 115, "top_nesting_level": 1 }, { "name": "dump_properties", "long_name": "dump_properties( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 5, "token_count": 117, "parameters": [ "self" ], "start_line": 397, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "_compile", "long_name": "_compile( self , obj , src , ext , cc_args , extra_postargs , pp_opts )", "filename": "fcompiler.py", "nloc": 32, "complexity": 8, "token_count": 211, "parameters": [ "self", "obj", "src", "ext", "cc_args", "extra_postargs", "pp_opts" ], "start_line": 418, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "module_options", "long_name": "module_options( self , module_dirs , module_build_dir )", "filename": "fcompiler.py", "nloc": 17, "complexity": 5, "token_count": 129, "parameters": [ "self", "module_dirs", "module_build_dir" ], "start_line": 456, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "library_option", "long_name": "library_option( self , lib )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "lib" ], "start_line": 474, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "library_dir_option", "long_name": "library_dir_option( self , dir )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "dir" ], "start_line": 476, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 256, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 483, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 }, { "name": "detect_language", "long_name": "detect_language( self , sources )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self", "sources" ], "start_line": 508, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir = None , libraries = None , library_dirs = None , runtime_library_dirs = None , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "fcompiler.py", "nloc": 42, "complexity": 11, "token_count": 306, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 511, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 1 }, { "name": "__get_cmd", "long_name": "__get_cmd( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 110, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 560, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__get_flags", "long_name": "__get_flags( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 120, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 575, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "_find_existing_fcompiler", "long_name": "_find_existing_fcompiler( compilers , osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 5, "token_count": 71, "parameters": [ "compilers", "osname", "platform" ], "start_line": 646, "end_line": 659, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_default_fcompiler", "long_name": "get_default_fcompiler( osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 21, "complexity": 9, "token_count": 135, "parameters": [ "osname", "platform" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "new_fcompiler", "long_name": "new_fcompiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "fcompiler.py", "nloc": 34, "complexity": 7, "token_count": 182, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 684, "end_line": 721, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "show_fcompilers", "long_name": "show_fcompilers( dist = None )", "filename": "fcompiler.py", "nloc": 41, "complexity": 8, "token_count": 261, "parameters": [ "dist" ], "start_line": 723, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "dummy_fortran_file.rm_file", "long_name": "dummy_fortran_file.rm_file( name = dummy_name , log_threshold = log . _global_log . threshold )", "filename": "fcompiler.py", "nloc": 8, "complexity": 3, "token_count": 84, "parameters": [ "name", "log_threshold" ], "start_line": 775, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "dummy_fortran_file", "long_name": "dummy_fortran_file( )", "filename": "fcompiler.py", "nloc": 9, "complexity": 1, "token_count": 46, "parameters": [], "start_line": 769, "end_line": 784, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "is_free_format", "long_name": "is_free_format( file )", "filename": "fcompiler.py", "nloc": 19, "complexity": 9, "token_count": 114, "parameters": [ "file" ], "start_line": 790, "end_line": 811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 609, "complexity": 163, "token_count": 4096, "diff_parsed": { "added": [ " '.F':'f77', # XXX: needs preprocessor", " '.F90':'f90', # XXX: needs preprocessor", " '.f95':'f90',", " }", " src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95','.F','.F90']" ], "deleted": [ " '.f95':'f90'}", " src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']" ] } } ] }, { "hash": "bea45934772282d176b7e494fbbce118171630dd", "msg": "Using _exec_command_posix on sunos.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-30T16:55:39+00:00", "author_timezone": 0, "committer_date": "2004-03-30T16:55:39+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "2d7c53055afd78acfddb455173498983b8da4993" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 2, "insertions": 2, "lines": 4, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -189,7 +189,7 @@ def exec_command( command,\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n- use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n+ use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n \n@@ -225,7 +225,7 @@ def exec_command( command,\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n- elif os.name=='posix' and sys.platform[:5]!='sunos':\n+ elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n", "added_lines": 2, "deleted_lines": 2, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 165, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 14, "token_count": 331, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 243, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 294, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 439, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 515, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 563, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 581, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 165, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 243, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 294, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 439, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 515, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 563, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 581, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 14, "token_count": 331, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 } ], "nloc": 420, "complexity": 132, "token_count": 3309, "diff_parsed": { "added": [ " use_shell = os.name=='posix'", " elif os.name=='posix':" ], "deleted": [ " use_shell = os.name=='posix' and sys.platform[:5]!='sunos'", " elif os.name=='posix' and sys.platform[:5]!='sunos':" ] } } ] }, { "hash": "d838c7960309a819ddd62cbf775bf171a08c5809", "msg": "Using os.path.realpath only on posix platforms.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-30T17:52:29+00:00", "author_timezone": 0, "committer_date": "2004-03-30T17:52:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "bea45934772282d176b7e494fbbce118171630dd" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 2, "insertions": 6, "lines": 8, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -120,6 +120,10 @@ def find_executable(exe, path=None):\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n+ if os.name=='posix':\n+ realpath = os.path.realpath\n+ else:\n+ realpath = lambda a:a\n \n suffices = ['']\n if os.name in ['nt','dos','os2']:\n@@ -144,11 +148,11 @@ def find_executable(exe, path=None):\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n- f_ext = os.path.realpath(fn+s)\n+ f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n- exe = os.path.realpath(exe)\n+ exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n", "added_lines": 6, "deleted_lines": 2, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = os.path.realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = os.path.realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 39, "complexity": 16, "token_count": 313, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 162, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 169, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 14, "token_count": 331, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 174, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 247, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 298, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 337, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 342, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 443, "end_line": 517, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 519, "end_line": 565, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 567, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 585, "end_line": 587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 35, "complexity": 15, "token_count": 299, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 165, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 14, "token_count": 331, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 170, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 243, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 294, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 333, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 338, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 439, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 515, "end_line": 561, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 563, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 581, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 39, "complexity": 16, "token_count": 313, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 } ], "nloc": 424, "complexity": 133, "token_count": 3323, "diff_parsed": { "added": [ " if os.name=='posix':", " realpath = os.path.realpath", " else:", " realpath = lambda a:a", " f_ext = realpath(fn+s)", " exe = realpath(exe)" ], "deleted": [ " f_ext = os.path.realpath(fn+s)", " exe = os.path.realpath(exe)" ] } } ] }, { "hash": "f061375e2cd34559bb1d08fe7e7d82dc700a1792", "msg": "Fixed exec_command when used under win32 cmd and a command contains spaces or is wrapped into quotes", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-31T18:46:30+00:00", "author_timezone": 0, "committer_date": "2004-03-31T18:46:30+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d838c7960309a819ddd62cbf775bf171a08c5809" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 11, "insertions": 34, "lines": 45, "files": 1, "dmm_unit_size": 0.42857142857142855, "dmm_unit_complexity": 0.42857142857142855, "dmm_unit_interfacing": 0.5714285714285714, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -39,6 +39,11 @@\n # Comment: also `cmd /c echo` will not work\n # but redefining environment variables do work.\n # posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n+# nt | win32 | Windows XP, Python 2.3.3\n+#\n+# Known bugs:\n+# - Tests, that send messages to stderr, fail when executed from MSYS prompt\n+# because the messages are lost at some point.\n \n __all__ = ['exec_command','find_executable']\n \n@@ -124,7 +129,8 @@ def find_executable(exe, path=None):\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n-\n+ if exe[0]=='\"':\n+ exe = exe[1:-1]\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n@@ -235,7 +241,8 @@ def exec_command( command,\n use_tee=use_tee,\n **env)\n else:\n- st = _exec_command(command, use_shell=use_shell, **env)\n+ st = _exec_command(command, use_shell=use_shell,\n+ use_tee=use_tee,**env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n@@ -339,11 +346,13 @@ def quote_arg(arg):\n return '\"%s\"' % arg\n return arg\n \n-def _exec_command( command, use_shell=None, **env ):\n+def _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n+ if use_tee is None:\n+ use_tee = os.name=='posix'\n \n using_command = 0\n if use_shell:\n@@ -372,7 +381,7 @@ def _exec_command( command, use_shell=None, **env ):\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n- argv = [os.environ['COMSPEC'],'/C']+argv\n+ argv = [os.environ['COMSPEC'],'/C'] + argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n@@ -395,7 +404,9 @@ def _exec_command( command, use_shell=None, **env ):\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n- if using_command:\n+ if 0 and using_command:\n+ #XXX: disabled for now as it does not work from cmd under win32.\n+ # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n@@ -426,17 +437,21 @@ def _exec_command( command, use_shell=None, **env ):\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n- # be treated as errors.\n+ # not be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n- text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n-\n+ #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n+ text = text + errmess\n+ print errmess\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n \n+ if use_tee:\n+ print text\n+\n return status, text\n \n \n@@ -582,9 +597,16 @@ def test_execute_in(**kws):\n os.remove(tmpfile)\n print 'ok'\n \n-def test_svn():\n- s,o = exec_command(['svn','status'])\n+def test_svn(**kws):\n+ s,o = exec_command(['svn','status'],**kws)\n assert s,(s,o)\n+ print 'svn ok'\n+\n+def test_cl(**kws):\n+ if os.name=='nt':\n+ s,o = exec_command(['cl','/V'],**kws)\n+ assert s,(s,o)\n+ print 'cl ok'\n \n if os.name=='posix':\n test = test_posix\n@@ -602,4 +624,5 @@ def test_svn():\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n- test_svn()\n+ test_svn(use_tee=1)\n+ test_cl(use_tee=1)\n", "added_lines": 34, "deleted_lines": 11, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n# nt | win32 | Windows XP, Python 2.3.3\n#\n# Known bugs:\n# - Tests, that send messages to stderr, fail when executed from MSYS prompt\n# because the messages are lost at some point.\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n if exe[0]=='\"':\n exe = exe[1:-1]\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell,\n use_tee=use_tee,**env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n if use_tee is None:\n use_tee = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C'] + argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if 0 and using_command:\n #XXX: disabled for now as it does not work from cmd under win32.\n # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # not be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n text = text + errmess\n print errmess\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n if use_tee:\n print text\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn(**kws):\n s,o = exec_command(['svn','status'],**kws)\n assert s,(s,o)\n print 'svn ok'\n\ndef test_cl(**kws):\n if os.name=='nt':\n s,o = exec_command(['cl','/V'],**kws)\n assert s,(s,o)\n print 'cl ok'\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn(use_tee=1)\n test_cl(use_tee=1)\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 61, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 72, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 104, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 41, "complexity": 17, "token_count": 330, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 168, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 175, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 46, "complexity": 14, "token_count": 335, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 180, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 254, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 305, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 344, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 81, "complexity": 20, "token_count": 571, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 349, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 458, "end_line": 532, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 534, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 582, "end_line": 598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( ** kws )", "filename": "exec_command.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "kws" ], "start_line": 600, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_cl", "long_name": "test_cl( ** kws )", "filename": "exec_command.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "kws" ], "start_line": 605, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 39, "complexity": 16, "token_count": 313, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 162, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 169, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 14, "token_count": 331, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 174, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 247, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 298, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 337, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 342, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 443, "end_line": 517, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 519, "end_line": 565, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 567, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 585, "end_line": 587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 552, "parameters": [ "command", "use_shell", "env" ], "start_line": 342, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( ** kws )", "filename": "exec_command.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "kws" ], "start_line": 600, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 41, "complexity": 17, "token_count": 330, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 585, "end_line": 587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_cl", "long_name": "test_cl( ** kws )", "filename": "exec_command.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "kws" ], "start_line": 605, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 46, "complexity": 14, "token_count": 335, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 180, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 81, "complexity": 20, "token_count": 571, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 349, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 } ], "nloc": 439, "complexity": 139, "token_count": 3418, "diff_parsed": { "added": [ "# nt | win32 | Windows XP, Python 2.3.3", "#", "# Known bugs:", "# - Tests, that send messages to stderr, fail when executed from MSYS prompt", "# because the messages are lost at some point.", " if exe[0]=='\"':", " exe = exe[1:-1]", " st = _exec_command(command, use_shell=use_shell,", " use_tee=use_tee,**env)", "def _exec_command( command, use_shell=None, use_tee = None, **env ):", " if use_tee is None:", " use_tee = os.name=='posix'", " argv = [os.environ['COMSPEC'],'/C'] + argv", " if 0 and using_command:", " #XXX: disabled for now as it does not work from cmd under win32.", " # Tests fail on msys", " # not be treated as errors.", " #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)", " text = text + errmess", " print errmess", " if use_tee:", " print text", "", "def test_svn(**kws):", " s,o = exec_command(['svn','status'],**kws)", " print 'svn ok'", "", "def test_cl(**kws):", " if os.name=='nt':", " s,o = exec_command(['cl','/V'],**kws)", " assert s,(s,o)", " print 'cl ok'", " test_svn(use_tee=1)", " test_cl(use_tee=1)" ], "deleted": [ "", " st = _exec_command(command, use_shell=use_shell, **env)", "def _exec_command( command, use_shell=None, **env ):", " argv = [os.environ['COMSPEC'],'/C']+argv", " if using_command:", " # be treated as errors.", " text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)", "", "def test_svn():", " s,o = exec_command(['svn','status'])", " test_svn()" ] } } ] }, { "hash": "442e9dd7b917d1deb7b143d254a2b0e5a986bd3d", "msg": "Improved debug messages", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-31T18:48:01+00:00", "author_timezone": 0, "committer_date": "2004-03-31T18:48:01+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f061375e2cd34559bb1d08fe7e7d82dc700a1792" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 3, "insertions": 2, "lines": 5, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/ccompiler.py", "new_path": "scipy_distutils/ccompiler.py", "filename": "ccompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -228,16 +228,15 @@ def new_compiler (plat=None,\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n-\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n- print msg\n+ print msg,'in scipy_distutils, trying from distutils..'\n module_name = module_name[6:]\n try:\n __import__(module_name)\n- except ImportError:\n+ except ImportError, msg:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n", "added_lines": 2, "deleted_lines": 3, "source_code": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n #log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n # % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg,'in scipy_distutils, trying from distutils..'\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError, msg:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "source_code_before": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n if log._global_log.threshold<2:\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n #log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n # % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 7, "token_count": 113, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 16, "complexity": 6, "token_count": 90, "parameters": [ "self" ], "start_line": 134, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 122, "parameters": [ "self", "force", "ok_status" ], "start_line": 175, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 188, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 214, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 } ], "methods_before": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 7, "token_count": 113, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 16, "complexity": 6, "token_count": 90, "parameters": [ "self" ], "start_line": 134, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 122, "parameters": [ "self", "force", "ok_status" ], "start_line": 175, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 214, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 188, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 214, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 } ], "nloc": 215, "complexity": 60, "token_count": 1601, "diff_parsed": { "added": [ " print msg,'in scipy_distutils, trying from distutils..'", " except ImportError, msg:" ], "deleted": [ "", " print msg", " except ImportError:" ] } } ] }, { "hash": "02ede8cb836abf41879998bffb70e962b7e3e2bc", "msg": "Workaround for MSVC6.0 when building c++ extensions", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-31T18:49:02+00:00", "author_timezone": 0, "committer_date": "2004-03-31T18:49:02+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "442e9dd7b917d1deb7b143d254a2b0e5a986bd3d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 0, "insertions": 5, "lines": 5, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_ext.py", "new_path": "scipy_distutils/command/build_ext.py", "filename": "build_ext.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -146,6 +146,11 @@ def build_extension(self, ext):\n \n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n+ if self.compiler.compiler_type=='msvc':\n+ # this hack worksaround 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", "added_lines": 5, "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 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 # this hack worksaround 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 fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n sources = filter(lambda s:type(s) is StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return 0\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n", "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n\n if sys.version[:3]>='2.3':\n kws = {'depends':ext.depends}\n else:\n kws = {}\n\n c_objects = []\n if c_sources:\n log.info(\"compling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n include_dirs = ext.include_dirs[:]\n module_dirs = ext.module_dirs[:]\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n \n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n \n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90']\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries(): \n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries,\n library_dirs=ext.library_dirs + c_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n sources = filter(lambda s:type(s) is StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return 0\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n", "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": 165, "complexity": 44, "token_count": 1076, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 197, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 313, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 310, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 333, "end_line": 344, "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": 162, "complexity": 43, "token_count": 1060, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 192, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 308, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 305, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 328, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 165, "complexity": 44, "token_count": 1076, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 197, "top_nesting_level": 1 } ], "nloc": 277, "complexity": 75, "token_count": 1796, "diff_parsed": { "added": [ " if self.compiler.compiler_type=='msvc':", " # this hack worksaround msvc compiler attributes", " # problem, msvc uses its own convention :(", " c_sources += cxx_sources", " cxx_sources = []" ], "deleted": [] } } ] }, { "hash": "d8e22e7e6479aa38b62c53f14ebaf98328131061", "msg": "Prepearing to tag scipy tree (unified micro version numbers)", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-02T21:40:12+00:00", "author_timezone": 0, "committer_date": "2004-04-02T21:40:12+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "02ede8cb836abf41879998bffb70e962b7e3e2bc" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 6, "insertions": 11, "lines": 17, "files": 4, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/scipy_base_version.py", "new_path": "scipy_base/scipy_base_version.py", "filename": "scipy_base_version.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,6 +1,6 @@\n major = 0\n minor = 2\n-micro = 1\n+micro = 2\n release_level = 'alpha'\n \n from __cvs_version__ import cvs_version\n", "added_lines": 1, "deleted_lines": 1, "source_code": "major = 0\nminor = 2\nmicro = 2\nrelease_level = 'alpha'\n\nfrom __cvs_version__ import cvs_version\ncvs_minor = cvs_version[-3]\ncvs_serial = cvs_version[-1]\n\nscipy_base_version = '%(major)d.%(minor)d.%(micro)d_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n", "source_code_before": "major = 0\nminor = 2\nmicro = 1\nrelease_level = 'alpha'\n\nfrom __cvs_version__ import cvs_version\ncvs_minor = cvs_version[-3]\ncvs_serial = cvs_version[-1]\n\nscipy_base_version = '%(major)d.%(minor)d.%(micro)d_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 9, "complexity": 0, "token_count": 41, "diff_parsed": { "added": [ "micro = 2" ], "deleted": [ "micro = 1" ] } }, { "old_path": "scipy_test/scipy_test_version.py", "new_path": "scipy_test/scipy_test_version.py", "filename": "scipy_test_version.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,6 +1,6 @@\n major = 0\n minor = 2\n-micro = 1\n+micro = 2\n release_level = 'alpha'\n \n from __cvs_version__ import cvs_version\n", "added_lines": 1, "deleted_lines": 1, "source_code": "major = 0\nminor = 2\nmicro = 2\nrelease_level = 'alpha'\n\nfrom __cvs_version__ import cvs_version\ncvs_minor = cvs_version[-3]\ncvs_serial = cvs_version[-1]\n\nscipy_test_version = '%(major)d.%(minor)d.%(micro)d_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n", "source_code_before": "major = 0\nminor = 2\nmicro = 1\nrelease_level = 'alpha'\n\nfrom __cvs_version__ import cvs_version\ncvs_minor = cvs_version[-3]\ncvs_serial = cvs_version[-1]\n\nscipy_test_version = '%(major)d.%(minor)d.%(micro)d_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 9, "complexity": 0, "token_count": 41, "diff_parsed": { "added": [ "micro = 2" ], "deleted": [ "micro = 1" ] } }, { "old_path": "setup.py", "new_path": "setup.py", "filename": "setup.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -45,12 +45,17 @@ def setup_package():\n minor = max([v.minor for v in versions])\n micro = max([v.micro for v in versions])\n release_level = min([v.release_level for v in versions])\n+ release_level = ''\n cvs_minor = reduce(lambda a,b:a+b,[v.cvs_minor for v in versions],0)\n cvs_serial = reduce(lambda a,b:a+b,[v.cvs_serial for v in versions],0)\n \n- scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\\n- '_%(release_level)s'\\\n- '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n+ if release_level:\n+ scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\\n+ '_%(release_level)s'\\\n+ '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n+ else:\n+ scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\\n+ '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n \n print 'SciPy Core Version %s' % scipy_core_version\n setup( version = scipy_core_version,\n", "added_lines": 8, "deleted_lines": 3, "source_code": "#!/usr/bin/env python\n\"\"\"\nBundle of SciPy core modules:\n scipy_test\n scipy_distutils\n scipy_base\n weave\n\nUsage:\n python setup.py install\n python setup.py sdist -f\n\"\"\"\n\nimport os\nimport sys\n\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict\nfrom scipy_distutils.misc_util import get_path, merge_config_dicts\n\nbundle_packages = ['scipy_distutils','scipy_test','scipy_base','weave']\n\ndef setup_package():\n old_path = os.getcwd()\n local_path = os.path.dirname(os.path.abspath(sys.argv[0]))\n os.chdir(local_path)\n sys.path.insert(0, local_path)\n\n try:\n configs = [{'name':'Scipy_core'}]\n versions = []\n for n in bundle_packages:\n sys.path.insert(0,os.path.join(local_path,n))\n try:\n mod = __import__('setup_'+n)\n configs.append(mod.configuration(parent_path=local_path))\n mod = __import__(n+'_version')\n versions.append(mod)\n finally:\n del sys.path[0]\n \n config_dict = merge_config_dicts(configs)\n\n major = max([v.major for v in versions])\n minor = max([v.minor for v in versions])\n micro = max([v.micro for v in versions])\n release_level = min([v.release_level for v in versions])\n release_level = ''\n cvs_minor = reduce(lambda a,b:a+b,[v.cvs_minor for v in versions],0)\n cvs_serial = reduce(lambda a,b:a+b,[v.cvs_serial for v in versions],0)\n\n if release_level:\n scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\\n '_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n else:\n scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n\n print 'SciPy Core Version %s' % scipy_core_version\n setup( version = scipy_core_version,\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = \"SciPy core modules: scipy_{distutils,test,base}\",\n license = \"SciPy License (BSD Style)\",\n url = \"http://www.scipy.org\",\n **config_dict\n )\n\n finally:\n del sys.path[0]\n os.chdir(old_path)\n\nif __name__ == \"__main__\":\n setup_package()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nBundle of SciPy core modules:\n scipy_test\n scipy_distutils\n scipy_base\n weave\n\nUsage:\n python setup.py install\n python setup.py sdist -f\n\"\"\"\n\nimport os\nimport sys\n\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import default_config_dict\nfrom scipy_distutils.misc_util import get_path, merge_config_dicts\n\nbundle_packages = ['scipy_distutils','scipy_test','scipy_base','weave']\n\ndef setup_package():\n old_path = os.getcwd()\n local_path = os.path.dirname(os.path.abspath(sys.argv[0]))\n os.chdir(local_path)\n sys.path.insert(0, local_path)\n\n try:\n configs = [{'name':'Scipy_core'}]\n versions = []\n for n in bundle_packages:\n sys.path.insert(0,os.path.join(local_path,n))\n try:\n mod = __import__('setup_'+n)\n configs.append(mod.configuration(parent_path=local_path))\n mod = __import__(n+'_version')\n versions.append(mod)\n finally:\n del sys.path[0]\n \n config_dict = merge_config_dicts(configs)\n\n major = max([v.major for v in versions])\n minor = max([v.minor for v in versions])\n micro = max([v.micro for v in versions])\n release_level = min([v.release_level for v in versions])\n cvs_minor = reduce(lambda a,b:a+b,[v.cvs_minor for v in versions],0)\n cvs_serial = reduce(lambda a,b:a+b,[v.cvs_serial for v in versions],0)\n\n scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\\n '_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n\n print 'SciPy Core Version %s' % scipy_core_version\n setup( version = scipy_core_version,\n maintainer = \"SciPy Developers\",\n maintainer_email = \"scipy-dev@scipy.org\",\n description = \"SciPy core modules: scipy_{distutils,test,base}\",\n license = \"SciPy License (BSD Style)\",\n url = \"http://www.scipy.org\",\n **config_dict\n )\n\n finally:\n del sys.path[0]\n os.chdir(old_path)\n\nif __name__ == \"__main__\":\n setup_package()\n", "methods": [ { "name": "setup_package", "long_name": "setup_package( )", "filename": "setup.py", "nloc": 44, "complexity": 11, "token_count": 326, "parameters": [], "start_line": 23, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 } ], "methods_before": [ { "name": "setup_package", "long_name": "setup_package( )", "filename": "setup.py", "nloc": 39, "complexity": 10, "token_count": 307, "parameters": [], "start_line": 23, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "setup_package", "long_name": "setup_package( )", "filename": "setup.py", "nloc": 44, "complexity": 11, "token_count": 326, "parameters": [], "start_line": 23, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 0 } ], "nloc": 63, "complexity": 11, "token_count": 371, "diff_parsed": { "added": [ " release_level = ''", " if release_level:", " scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\", " '_%(release_level)s'\\", " '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())", " else:", " scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\", " '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())" ], "deleted": [ " scipy_core_version = '%(major)d.%(minor)d.%(micro)d'\\", " '_%(release_level)s'\\", " '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())" ] } }, { "old_path": "weave/weave_version.py", "new_path": "weave/weave_version.py", "filename": "weave_version.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,6 +1,6 @@\n major = 0\n minor = 2\n-micro = 1\n+micro = 2\n release_level = 'alpha'\n \n from __cvs_version__ import cvs_version\n", "added_lines": 1, "deleted_lines": 1, "source_code": "major = 0\nminor = 2\nmicro = 2\nrelease_level = 'alpha'\n\nfrom __cvs_version__ import cvs_version\ncvs_minor = cvs_version[-3]\ncvs_serial = cvs_version[-1]\n\nweave_version = '%(major)d.%(minor)d.%(micro)d_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n", "source_code_before": "major = 0\nminor = 2\nmicro = 1\nrelease_level = 'alpha'\n\nfrom __cvs_version__ import cvs_version\ncvs_minor = cvs_version[-3]\ncvs_serial = cvs_version[-1]\n\nweave_version = '%(major)d.%(minor)d.%(micro)d_%(release_level)s'\\\n '_%(cvs_minor)d.%(cvs_serial)d' % (locals ())\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 9, "complexity": 0, "token_count": 41, "diff_parsed": { "added": [ "micro = 2" ], "deleted": [ "micro = 1" ] } } ] }, { "hash": "e161453c5b18f2130f5b89bc7dbb7d417aa5b9cb", "msg": "Fixed building c++ libraries when using msvc 6.0", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-03T01:06:25+00:00", "author_timezone": 0, "committer_date": "2004-04-03T01:06:25+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d8e22e7e6479aa38b62c53f14ebaf98328131061" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 0, "insertions": 6, "lines": 6, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_clib.py", "new_path": "scipy_distutils/command/build_clib.py", "filename": "build_clib.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -171,6 +171,12 @@ def build_libraries(self, libraries):\n c_sources, cxx_sources, f_sources, fmodule_sources \\\n = filter_sources(sources)\n \n+ if self.compiler.compiler_type=='msvc':\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 fmodule_sources:\n print 'XXX: Fortran 90 module support not implemented or tested'\n f_sources.extend(fmodule_sources)\n", "added_lines": 6, "deleted_lines": 0, "source_code": "\"\"\" Modified version of build_clib that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nimport re\nfrom glob import glob\nfrom types import *\nfrom distutils.command.build_clib import build_clib as old_build_clib\nfrom distutils.command.build_clib import show_compilers\n\nfrom scipy_distutils import log, misc_util\nfrom distutils.dep_util import newer_group\nfrom scipy_distutils.misc_util import filter_sources, \\\n has_f_sources, has_cxx_sources\n\ndef get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n\n return headers\n\ndef get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\nclass build_clib(old_build_clib):\n\n description = \"build C/C++/F libraries used by Python extensions\"\n\n user_options = old_build_clib.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_clib.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_clib.finalize_options(self)\n self.set_undefined_options('build_ext',\n ('fcompiler', 'fcompiler'))\n\n #XXX: This is hackish and probably unnecessary,\n # could we get rid of this?\n from scipy_distutils import misc_util\n extra_includes = misc_util.get_environ_include_dirs()\n if extra_includes:\n print \"XXX: are you sure you'll need PYTHONINCLUDES env. variable??\"\n self.include_dirs.extend(extra_includes)\n\n return\n\n def have_f_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_f_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def have_cxx_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_cxx_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def run(self):\n if not self.libraries:\n return\n\n # Make sure that library sources are complete.\n for (lib_name, build_info) in self.libraries:\n if not misc_util.all_strings(build_info.get('sources',[])):\n raise TypeError,'Library \"%s\" sources contains unresolved'\\\n ' items (call build_src before built_clib).' % (lib_name)\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=self.have_cxx_sources())\n\n libraries = self.libraries\n self.libraries = None\n self.compiler.customize_cmd(self)\n self.libraries = libraries\n\n self.compiler.show_customization()\n\n if self.have_f_sources():\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 \n libraries = self.libraries\n self.libraries = None\n self.fcompiler.customize_cmd(self)\n self.libraries = libraries\n\n self.fcompiler.show_customization()\n\n self.build_libraries(self.libraries)\n return\n\n def get_source_files(self):\n from build_ext import is_local_src_dir\n self.check_library_list(self.libraries)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n for (lib_name, build_info) in self.libraries:\n sources = build_info.get('sources',[])\n sources = filter(lambda s:type(s) is StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n depends = build_info.get('depends',[])\n for d in 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 build_libraries(self, libraries):\n\n compiler = self.compiler\n fcompiler = self.fcompiler\n\n for (lib_name, build_info) in libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n\n lib_file = compiler.library_filename(lib_name,\n output_dir=self.build_clib)\n\n depends = sources + build_info.get('depends',[])\n if not (self.force or newer_group(depends, lib_file, 'newer')):\n log.debug(\"skipping '%s' library (up-to-date)\", lib_name)\n continue\n else:\n log.info(\"building '%s' library\", lib_name)\n\n macros = build_info.get('macros')\n include_dirs = build_info.get('include_dirs')\n extra_postargs = build_info.get('extra_compiler_args') or []\n\n c_sources, cxx_sources, f_sources, fmodule_sources \\\n = filter_sources(sources)\n\n if self.compiler.compiler_type=='msvc':\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 fmodule_sources:\n print 'XXX: Fortran 90 module support not implemented or tested'\n f_sources.extend(fmodule_sources)\n\n objects = []\n if c_sources:\n log.info(\"compling C sources\")\n objects = compiler.compile(c_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\n if cxx_sources:\n log.info(\"compling C++ sources\")\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n cxx_objects = compiler.compile(cxx_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 objects.extend(cxx_objects)\n\n self.compiler.compiler_so[0] = old_compiler\n\n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects = 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=[])\n objects.extend(f_objects)\n\n self.compiler.create_static_lib(objects, lib_name,\n output_dir=self.build_clib,\n debug=self.debug)\n return\n", "source_code_before": "\"\"\" Modified version of build_clib that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nimport re\nfrom glob import glob\nfrom types import *\nfrom distutils.command.build_clib import build_clib as old_build_clib\nfrom distutils.command.build_clib import show_compilers\n\nfrom scipy_distutils import log, misc_util\nfrom distutils.dep_util import newer_group\nfrom scipy_distutils.misc_util import filter_sources, \\\n has_f_sources, has_cxx_sources\n\ndef get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n\n return headers\n\ndef get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\nclass build_clib(old_build_clib):\n\n description = \"build C/C++/F libraries used by Python extensions\"\n\n user_options = old_build_clib.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_clib.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_clib.finalize_options(self)\n self.set_undefined_options('build_ext',\n ('fcompiler', 'fcompiler'))\n\n #XXX: This is hackish and probably unnecessary,\n # could we get rid of this?\n from scipy_distutils import misc_util\n extra_includes = misc_util.get_environ_include_dirs()\n if extra_includes:\n print \"XXX: are you sure you'll need PYTHONINCLUDES env. variable??\"\n self.include_dirs.extend(extra_includes)\n\n return\n\n def have_f_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_f_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def have_cxx_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_cxx_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def run(self):\n if not self.libraries:\n return\n\n # Make sure that library sources are complete.\n for (lib_name, build_info) in self.libraries:\n if not misc_util.all_strings(build_info.get('sources',[])):\n raise TypeError,'Library \"%s\" sources contains unresolved'\\\n ' items (call build_src before built_clib).' % (lib_name)\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=self.have_cxx_sources())\n\n libraries = self.libraries\n self.libraries = None\n self.compiler.customize_cmd(self)\n self.libraries = libraries\n\n self.compiler.show_customization()\n\n if self.have_f_sources():\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 \n libraries = self.libraries\n self.libraries = None\n self.fcompiler.customize_cmd(self)\n self.libraries = libraries\n\n self.fcompiler.show_customization()\n\n self.build_libraries(self.libraries)\n return\n\n def get_source_files(self):\n from build_ext import is_local_src_dir\n self.check_library_list(self.libraries)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n for (lib_name, build_info) in self.libraries:\n sources = build_info.get('sources',[])\n sources = filter(lambda s:type(s) is StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n depends = build_info.get('depends',[])\n for d in 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 build_libraries(self, libraries):\n\n compiler = self.compiler\n fcompiler = self.fcompiler\n\n for (lib_name, build_info) in libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n\n lib_file = compiler.library_filename(lib_name,\n output_dir=self.build_clib)\n\n depends = sources + build_info.get('depends',[])\n if not (self.force or newer_group(depends, lib_file, 'newer')):\n log.debug(\"skipping '%s' library (up-to-date)\", lib_name)\n continue\n else:\n log.info(\"building '%s' library\", lib_name)\n\n macros = build_info.get('macros')\n include_dirs = build_info.get('include_dirs')\n extra_postargs = build_info.get('extra_compiler_args') or []\n\n c_sources, cxx_sources, f_sources, fmodule_sources \\\n = filter_sources(sources)\n\n if fmodule_sources:\n print 'XXX: Fortran 90 module support not implemented or tested'\n f_sources.extend(fmodule_sources)\n\n objects = []\n if c_sources:\n log.info(\"compling C sources\")\n objects = compiler.compile(c_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\n if cxx_sources:\n log.info(\"compling C++ sources\")\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n cxx_objects = compiler.compile(cxx_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 objects.extend(cxx_objects)\n\n self.compiler.compiler_so[0] = old_compiler\n\n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects = 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=[])\n objects.extend(f_objects)\n\n self.compiler.create_static_lib(objects, lib_name,\n output_dir=self.build_clib,\n debug=self.debug)\n return\n", "methods": [ { "name": "get_headers", "long_name": "get_headers( directory_list )", "filename": "build_clib.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "directory_list" ], "start_line": 18, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_directories", "long_name": "get_directories( list_of_sources )", "filename": "build_clib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "list_of_sources" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_clib.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 45, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_clib.py", "nloc": 10, "complexity": 2, "token_count": 48, "parameters": [ "self" ], "start_line": 50, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "have_f_sources", "long_name": "have_f_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 65, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "have_cxx_sources", "long_name": "have_cxx_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 71, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_clib.py", "nloc": 31, "complexity": 5, "token_count": 220, "parameters": [ "self" ], "start_line": 77, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_clib.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 122, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_clib.py", "nloc": 17, "complexity": 5, "token_count": 131, "parameters": [ "self" ], "start_line": 118, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 64, "complexity": 12, "token_count": 400, "parameters": [ "self", "libraries" ], "start_line": 143, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_headers", "long_name": "get_headers( directory_list )", "filename": "build_clib.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "directory_list" ], "start_line": 18, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_directories", "long_name": "get_directories( list_of_sources )", "filename": "build_clib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "list_of_sources" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_clib.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 45, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_clib.py", "nloc": 10, "complexity": 2, "token_count": 48, "parameters": [ "self" ], "start_line": 50, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "have_f_sources", "long_name": "have_f_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 65, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "have_cxx_sources", "long_name": "have_cxx_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 71, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_clib.py", "nloc": 31, "complexity": 5, "token_count": 220, "parameters": [ "self" ], "start_line": 77, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_clib.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 122, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_clib.py", "nloc": 17, "complexity": 5, "token_count": 131, "parameters": [ "self" ], "start_line": 118, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 61, "complexity": 11, "token_count": 384, "parameters": [ "self", "libraries" ], "start_line": 143, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 74, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 64, "complexity": 12, "token_count": 400, "parameters": [ "self", "libraries" ], "start_line": 143, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 } ], "nloc": 176, "complexity": 41, "token_count": 1129, "diff_parsed": { "added": [ " if self.compiler.compiler_type=='msvc':", " # this hack works around the msvc compiler attributes", " # problem, msvc uses its own convention :(", " c_sources += cxx_sources", " cxx_sources = []", "" ], "deleted": [] } } ] }, { "hash": "4a912cbe99930457850aad03dd2f9a44a4ddf58d", "msg": "Fixed win32 cmd and msys ports.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-03T01:31:21+00:00", "author_timezone": 0, "committer_date": "2004-04-03T01:31:21+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "e161453c5b18f2130f5b89bc7dbb7d417aa5b9cb" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 11, "insertions": 16, "lines": 27, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -72,7 +72,7 @@ def get_pythonexe():\n def splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n- log.info('splitcmdline(%r)' % (line))\n+ log.debug('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n@@ -285,9 +285,11 @@ def _exec_command_posix( command,\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n+\n if stsfile is not None:\n f = open(stsfile,'r')\n- status = int(f.read())\n+ status_text = f.read()\n+ status = int(status_text)\n f.close()\n os.remove(stsfile)\n \n@@ -370,7 +372,7 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n- \n+\n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n@@ -378,11 +380,11 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n- argv[0] = quote_arg(argv[0])\n- if os.name in ['nt','dos']:\n- # argv[0] might be internal command\n- argv = [os.environ['COMSPEC'],'/C'] + argv\n- using_command = 1\n+ if os.name in ['nt','dos']:\n+ # argv[0] might be internal command\n+ argv = [os.environ['COMSPEC'],'/C'] + argv\n+ using_command = 1\n+\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n@@ -401,18 +403,21 @@ def _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n \n+ argv0 = argv[0]\n+ if not using_command:\n+ argv[0] = quote_arg(argv0)\n+\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n- if 0 and using_command:\n+ if using_command:\n #XXX: disabled for now as it does not work from cmd under win32.\n # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n-\n try:\n- status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n+ status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n", "added_lines": 16, "deleted_lines": 11, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n# nt | win32 | Windows XP, Python 2.3.3\n#\n# Known bugs:\n# - Tests, that send messages to stderr, fail when executed from MSYS prompt\n# because the messages are lost at some point.\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.debug('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n if exe[0]=='\"':\n exe = exe[1:-1]\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell,\n use_tee=use_tee,**env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n\n if stsfile is not None:\n f = open(stsfile,'r')\n status_text = f.read()\n status = int(status_text)\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n if use_tee is None:\n use_tee = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n\n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C'] + argv\n using_command = 1\n\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n argv0 = argv[0]\n if not using_command:\n argv[0] = quote_arg(argv0)\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n #XXX: disabled for now as it does not work from cmd under win32.\n # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # not be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n text = text + errmess\n print errmess\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n if use_tee:\n print text\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn(**kws):\n s,o = exec_command(['svn','status'],**kws)\n assert s,(s,o)\n print 'svn ok'\n\ndef test_cl(**kws):\n if os.name=='nt':\n s,o = exec_command(['cl','/V'],**kws)\n assert s,(s,o)\n print 'cl ok'\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn(use_tee=1)\n test_cl(use_tee=1)\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n# nt | win32 | Windows XP, Python 2.3.3\n#\n# Known bugs:\n# - Tests, that send messages to stderr, fail when executed from MSYS prompt\n# because the messages are lost at some point.\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n if exe[0]=='\"':\n exe = exe[1:-1]\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell,\n use_tee=use_tee,**env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n if use_tee is None:\n use_tee = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n argv[0] = quote_arg(argv[0])\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C'] + argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if 0 and using_command:\n #XXX: disabled for now as it does not work from cmd under win32.\n # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # not be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n text = text + errmess\n print errmess\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n if use_tee:\n print text\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn(**kws):\n s,o = exec_command(['svn','status'],**kws)\n assert s,(s,o)\n print 'svn ok'\n\ndef test_cl(**kws):\n if os.name=='nt':\n s,o = exec_command(['cl','/V'],**kws)\n assert s,(s,o)\n print 'cl ok'\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn(use_tee=1)\n test_cl(use_tee=1)\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 61, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 72, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 104, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 41, "complexity": 17, "token_count": 330, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 168, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 175, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 46, "complexity": 14, "token_count": 335, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 180, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 41, "complexity": 8, "token_count": 244, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 254, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 307, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 346, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 83, "complexity": 20, "token_count": 573, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 351, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 463, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 539, "end_line": 585, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 587, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( ** kws )", "filename": "exec_command.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "kws" ], "start_line": 605, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_cl", "long_name": "test_cl( ** kws )", "filename": "exec_command.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "kws" ], "start_line": 610, "end_line": 614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 61, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 72, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 104, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 41, "complexity": 17, "token_count": 330, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 168, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 175, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 46, "complexity": 14, "token_count": 335, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 180, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 254, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 305, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 344, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 81, "complexity": 20, "token_count": 571, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 349, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 458, "end_line": 532, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 534, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 582, "end_line": 598, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( ** kws )", "filename": "exec_command.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "kws" ], "start_line": 600, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_cl", "long_name": "test_cl( ** kws )", "filename": "exec_command.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "kws" ], "start_line": 605, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 41, "complexity": 8, "token_count": 244, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 254, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 72, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 83, "complexity": 20, "token_count": 573, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 351, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 } ], "nloc": 442, "complexity": 139, "token_count": 3423, "diff_parsed": { "added": [ " log.debug('splitcmdline(%r)' % (line))", "", " status_text = f.read()", " status = int(status_text)", "", " if os.name in ['nt','dos']:", " # argv[0] might be internal command", " argv = [os.environ['COMSPEC'],'/C'] + argv", " using_command = 1", "", " argv0 = argv[0]", " if not using_command:", " argv[0] = quote_arg(argv0)", "", " if using_command:", " status = spawn_command(os.P_WAIT,argv0,argv,os.environ)" ], "deleted": [ " log.info('splitcmdline(%r)' % (line))", " status = int(f.read())", "", " argv[0] = quote_arg(argv[0])", " if os.name in ['nt','dos']:", " # argv[0] might be internal command", " argv = [os.environ['COMSPEC'],'/C'] + argv", " using_command = 1", " if 0 and using_command:", "", " status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)" ] } } ] }, { "hash": "58618b0bb463a22a8938dad2a47ce9dda31f7c13", "msg": "Fixed --inplace building of swig extensions: .py files are put (by 'swig -outdir') to the same directory where extension files are generated.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-05T17:39:50+00:00", "author_timezone": 0, "committer_date": "2004-04-05T17:39:50+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4a912cbe99930457850aad03dd2f9a44a4ddf58d" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 6, "insertions": 15, "lines": 21, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.3333333333333333, "dmm_unit_interfacing": 0.6666666666666666, "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": "@@ -39,7 +39,7 @@ def initialize_options(self):\n self.build_lib = None\n self.build_base = None\n self.force = None\n- self.inplace = 0\n+ self.inplace = None\n self.package_dir = None\n self.f2pyflags = None\n self.swigflags = None\n@@ -57,6 +57,9 @@ def finalize_options(self):\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@@ -112,6 +115,10 @@ def build_extension_sources(self, ext):\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.swig_sources(sources, ext)\n@@ -142,7 +149,7 @@ def generate_sources(self, sources, extension):\n if not func_sources:\n return new_sources\n if self.inplace:\n- build_dir = '.'\n+ build_dir = self.ext_target_dir\n else:\n build_dir = self.build_src\n self.mkpath(build_dir)\n@@ -303,9 +310,11 @@ def swig_sources(self, sources, extension):\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 = os.path.join(self.build_src,\n 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@@ -338,10 +347,9 @@ def swig_sources(self, sources, extension):\n % (target_file))\n target_dirs.append(target_dir)\n new_sources.append(target_file)\n- py_files.append(os.path.join(target_dir,name+'.py'))\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-\n else:\n new_sources.append(source)\n \n@@ -350,7 +358,7 @@ def swig_sources(self, sources, extension):\n \n if skip_swig:\n return new_sources + py_files\n- \n+\n map(self.mkpath, target_dirs)\n swig = self.find_swig()\n swig_cmd = [swig, \"-python\"]\n@@ -364,7 +372,8 @@ def swig_sources(self, sources, extension):\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 + [\"-o\", target, 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", "added_lines": 15, "deleted_lines": 6, "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\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.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 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 = os.path.join(self.build_src,\n 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 = os.path.join(self.build_src,\n 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\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\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 = 0\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\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 sources = self.generate_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 = '.'\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 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 = os.path.join(self.build_src,\n 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 else:\n target_dir = os.path.join(self.build_src,\n os.path.dirname(base))\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(target_dir,name+'.py'))\n swig_sources.append(source)\n swig_targets[source] = new_sources[-1]\n\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 + [\"-o\", target, source])\n else:\n log.debug(\" skipping '%s' swig interface (up-to-date)\" \\\n % (source))\n\n return new_sources + py_files\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": 22, "complexity": 4, "token_count": 197, "parameters": [ "self", "ext" ], "start_line": 108, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "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": 141, "end_line": 164, "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": 166, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 108, "complexity": 22, "token_count": 826, "parameters": [ "self", "sources", "extension" ], "start_line": 177, "end_line": 294, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 118, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 81, "complexity": 17, "token_count": 543, "parameters": [ "self", "sources", "extension" ], "start_line": 296, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 86, "top_nesting_level": 1 }, { "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": 389, "end_line": 398, "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": 400, "end_line": 409, "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": 411, "end_line": 416, "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": 425, "end_line": 437, "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": 22, "complexity": 6, "token_count": 157, "parameters": [ "self" ], "start_line": 48, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "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": 75, "end_line": 79, "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": 81, "end_line": 90, "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": 92, "end_line": 103, "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": 19, "complexity": 3, "token_count": 174, "parameters": [ "self", "ext" ], "start_line": 105, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "generate_sources", "long_name": "generate_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 24, "complexity": 8, "token_count": 141, "parameters": [ "self", "sources", "extension" ], "start_line": 134, "end_line": 157, "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": 159, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 108, "complexity": 22, "token_count": 826, "parameters": [ "self", "sources", "extension" ], "start_line": 170, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 118, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 78, "complexity": 17, "token_count": 530, "parameters": [ "self", "sources", "extension" ], "start_line": 289, "end_line": 372, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 84, "top_nesting_level": 1 }, { "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": 380, "end_line": 389, "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": 391, "end_line": 400, "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": 402, "end_line": 407, "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": 416, "end_line": 428, "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": 24, "complexity": 8, "token_count": 143, "parameters": [ "self", "sources", "extension" ], "start_line": 141, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "build_extension_sources", "long_name": "build_extension_sources( self , ext )", "filename": "build_src.py", "nloc": 22, "complexity": 4, "token_count": 197, "parameters": [ "self", "ext" ], "start_line": 108, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "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": "swig_sources", "long_name": "swig_sources( self , sources , extension )", "filename": "build_src.py", "nloc": 81, "complexity": 17, "token_count": 543, "parameters": [ "self", "sources", "extension" ], "start_line": 296, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 86, "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 } ], "nloc": 373, "complexity": 83, "token_count": 2551, "diff_parsed": { "added": [ " self.inplace = None", " if self.inplace is None:", " build_ext = self.get_finalized_command('build_ext')", " self.inplace = build_ext.inplace", " if self.inplace:", " build_py = self.get_finalized_command('build_py')", " self.ext_target_dir = build_py.get_package_dir(package)", "", " build_dir = self.ext_target_dir", " py_target_dir = self.ext_target_dir", " py_target_dir = target_dir", " py_files.append(os.path.join(py_target_dir, name+'.py'))", "", " self.spawn(swig_cmd + self.swigflags \\", " + [\"-o\", target, '-outdir', py_target_dir, source])" ], "deleted": [ " self.inplace = 0", " build_dir = '.'", " py_files.append(os.path.join(target_dir,name+'.py'))", "", "", " self.spawn(swig_cmd + self.swigflags + [\"-o\", target, source])" ] } } ] }, { "hash": "0e692908548f52b8462db02825443594600444d0", "msg": "Fixed get_path output.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-05T19:53:57+00:00", "author_timezone": 0, "committer_date": "2004-04-05T19:53:57+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "58618b0bb463a22a8938dad2a47ce9dda31f7c13" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": 0.0, "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": "@@ -82,7 +82,7 @@ def get_path(mod_name,parent_path=None):\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\n- return d\n+ return d or '.'\n \n def add_local_to_path(mod_name):\n local_path = get_path(mod_name)\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 name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_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\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\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\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() function in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir']\n\ndef default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef _get_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\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\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": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 196, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 210, "end_line": 215, "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": 217, "end_line": 218, "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": 220, "end_line": 235, "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": 237, "end_line": 241, "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": 243, "end_line": 246, "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": 257, "end_line": 269, "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": 270, "end_line": 271, "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": 272, "end_line": 283, "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": 284, "end_line": 285, "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": 293, "end_line": 296, "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": 297, "end_line": 298, "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": 299, "end_line": 300, "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": 309, "end_line": 325, "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": 327, "end_line": 332, "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": 334, "end_line": 339, "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": 341, "end_line": 346, "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": 348, "end_line": 368, "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": 370, "end_line": 388, "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": 390, "end_line": 398, "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": 400, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "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": 5, "token_count": 124, "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": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 196, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 210, "end_line": 215, "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": 217, "end_line": 218, "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": 220, "end_line": 235, "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": 237, "end_line": 241, "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": 243, "end_line": 246, "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": 257, "end_line": 269, "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": 270, "end_line": 271, "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": 272, "end_line": 283, "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": 284, "end_line": 285, "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": 293, "end_line": 296, "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": 297, "end_line": 298, "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": 299, "end_line": 300, "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": 309, "end_line": 325, "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": 327, "end_line": 332, "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": 334, "end_line": 339, "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": 341, "end_line": 346, "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": 348, "end_line": 368, "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": 370, "end_line": 388, "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": 390, "end_line": 398, "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": 400, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 92, "top_nesting_level": 0 } ], "changed_methods": [ { "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 } ], "nloc": 362, "complexity": 121, "token_count": 2686, "diff_parsed": { "added": [ " return d or '.'" ], "deleted": [ " return d" ] } } ] }, { "hash": "63bbe4c6aa8f95d71b86223e731eba981951c3ad", "msg": "sdist: ignore hidden and temporary files", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-05T20:12:20+00:00", "author_timezone": 0, "committer_date": "2004-04-05T20:12:20+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "0e692908548f52b8462db02825443594600444d0" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 0, "insertions": 4, "lines": 4, "files": 2, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_clib.py", "new_path": "scipy_distutils/command/build_clib.py", "filename": "build_clib.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -124,6 +124,8 @@ def visit_func(filenames,dirname,names):\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", "added_lines": 2, "deleted_lines": 0, "source_code": "\"\"\" Modified version of build_clib that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nimport re\nfrom glob import glob\nfrom types import *\nfrom distutils.command.build_clib import build_clib as old_build_clib\nfrom distutils.command.build_clib import show_compilers\n\nfrom scipy_distutils import log, misc_util\nfrom distutils.dep_util import newer_group\nfrom scipy_distutils.misc_util import filter_sources, \\\n has_f_sources, has_cxx_sources\n\ndef get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n\n return headers\n\ndef get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\nclass build_clib(old_build_clib):\n\n description = \"build C/C++/F libraries used by Python extensions\"\n\n user_options = old_build_clib.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_clib.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_clib.finalize_options(self)\n self.set_undefined_options('build_ext',\n ('fcompiler', 'fcompiler'))\n\n #XXX: This is hackish and probably unnecessary,\n # could we get rid of this?\n from scipy_distutils import misc_util\n extra_includes = misc_util.get_environ_include_dirs()\n if extra_includes:\n print \"XXX: are you sure you'll need PYTHONINCLUDES env. variable??\"\n self.include_dirs.extend(extra_includes)\n\n return\n\n def have_f_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_f_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def have_cxx_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_cxx_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def run(self):\n if not self.libraries:\n return\n\n # Make sure that library sources are complete.\n for (lib_name, build_info) in self.libraries:\n if not misc_util.all_strings(build_info.get('sources',[])):\n raise TypeError,'Library \"%s\" sources contains unresolved'\\\n ' items (call build_src before built_clib).' % (lib_name)\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=self.have_cxx_sources())\n\n libraries = self.libraries\n self.libraries = None\n self.compiler.customize_cmd(self)\n self.libraries = libraries\n\n self.compiler.show_customization()\n\n if self.have_f_sources():\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 \n libraries = self.libraries\n self.libraries = None\n self.fcompiler.customize_cmd(self)\n self.libraries = libraries\n\n self.fcompiler.show_customization()\n\n self.build_libraries(self.libraries)\n return\n\n def get_source_files(self):\n from build_ext import is_local_src_dir\n self.check_library_list(self.libraries)\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 for (lib_name, build_info) in self.libraries:\n sources = build_info.get('sources',[])\n sources = filter(lambda s:type(s) is StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n depends = build_info.get('depends',[])\n for d in 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 build_libraries(self, libraries):\n\n compiler = self.compiler\n fcompiler = self.fcompiler\n\n for (lib_name, build_info) in libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n\n lib_file = compiler.library_filename(lib_name,\n output_dir=self.build_clib)\n\n depends = sources + build_info.get('depends',[])\n if not (self.force or newer_group(depends, lib_file, 'newer')):\n log.debug(\"skipping '%s' library (up-to-date)\", lib_name)\n continue\n else:\n log.info(\"building '%s' library\", lib_name)\n\n macros = build_info.get('macros')\n include_dirs = build_info.get('include_dirs')\n extra_postargs = build_info.get('extra_compiler_args') or []\n\n c_sources, cxx_sources, f_sources, fmodule_sources \\\n = filter_sources(sources)\n\n if self.compiler.compiler_type=='msvc':\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 fmodule_sources:\n print 'XXX: Fortran 90 module support not implemented or tested'\n f_sources.extend(fmodule_sources)\n\n objects = []\n if c_sources:\n log.info(\"compling C sources\")\n objects = compiler.compile(c_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\n if cxx_sources:\n log.info(\"compling C++ sources\")\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n cxx_objects = compiler.compile(cxx_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 objects.extend(cxx_objects)\n\n self.compiler.compiler_so[0] = old_compiler\n\n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects = 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=[])\n objects.extend(f_objects)\n\n self.compiler.create_static_lib(objects, lib_name,\n output_dir=self.build_clib,\n debug=self.debug)\n return\n", "source_code_before": "\"\"\" Modified version of build_clib that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nimport re\nfrom glob import glob\nfrom types import *\nfrom distutils.command.build_clib import build_clib as old_build_clib\nfrom distutils.command.build_clib import show_compilers\n\nfrom scipy_distutils import log, misc_util\nfrom distutils.dep_util import newer_group\nfrom scipy_distutils.misc_util import filter_sources, \\\n has_f_sources, has_cxx_sources\n\ndef get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob(os.path.join(dir,\"*.h\")) #XXX: *.hpp files??\n headers.extend(head)\n\n return headers\n\ndef get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n return direcs\n\nclass build_clib(old_build_clib):\n\n description = \"build C/C++/F libraries used by Python extensions\"\n\n user_options = old_build_clib.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_clib.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_clib.finalize_options(self)\n self.set_undefined_options('build_ext',\n ('fcompiler', 'fcompiler'))\n\n #XXX: This is hackish and probably unnecessary,\n # could we get rid of this?\n from scipy_distutils import misc_util\n extra_includes = misc_util.get_environ_include_dirs()\n if extra_includes:\n print \"XXX: are you sure you'll need PYTHONINCLUDES env. variable??\"\n self.include_dirs.extend(extra_includes)\n\n return\n\n def have_f_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_f_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def have_cxx_sources(self):\n for (lib_name, build_info) in self.libraries:\n if has_cxx_sources(build_info.get('sources',[])):\n return 1\n return 0\n\n def run(self):\n if not self.libraries:\n return\n\n # Make sure that library sources are complete.\n for (lib_name, build_info) in self.libraries:\n if not misc_util.all_strings(build_info.get('sources',[])):\n raise TypeError,'Library \"%s\" sources contains unresolved'\\\n ' items (call build_src before built_clib).' % (lib_name)\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=self.have_cxx_sources())\n\n libraries = self.libraries\n self.libraries = None\n self.compiler.customize_cmd(self)\n self.libraries = libraries\n\n self.compiler.show_customization()\n\n if self.have_f_sources():\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 \n libraries = self.libraries\n self.libraries = None\n self.fcompiler.customize_cmd(self)\n self.libraries = libraries\n\n self.fcompiler.show_customization()\n\n self.build_libraries(self.libraries)\n return\n\n def get_source_files(self):\n from build_ext import is_local_src_dir\n self.check_library_list(self.libraries)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n for (lib_name, build_info) in self.libraries:\n sources = build_info.get('sources',[])\n sources = filter(lambda s:type(s) is StringType,sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n depends = build_info.get('depends',[])\n for d in 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 build_libraries(self, libraries):\n\n compiler = self.compiler\n fcompiler = self.fcompiler\n\n for (lib_name, build_info) in libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n\n lib_file = compiler.library_filename(lib_name,\n output_dir=self.build_clib)\n\n depends = sources + build_info.get('depends',[])\n if not (self.force or newer_group(depends, lib_file, 'newer')):\n log.debug(\"skipping '%s' library (up-to-date)\", lib_name)\n continue\n else:\n log.info(\"building '%s' library\", lib_name)\n\n macros = build_info.get('macros')\n include_dirs = build_info.get('include_dirs')\n extra_postargs = build_info.get('extra_compiler_args') or []\n\n c_sources, cxx_sources, f_sources, fmodule_sources \\\n = filter_sources(sources)\n\n if self.compiler.compiler_type=='msvc':\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 fmodule_sources:\n print 'XXX: Fortran 90 module support not implemented or tested'\n f_sources.extend(fmodule_sources)\n\n objects = []\n if c_sources:\n log.info(\"compling C sources\")\n objects = compiler.compile(c_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\n if cxx_sources:\n log.info(\"compling C++ sources\")\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n cxx_objects = compiler.compile(cxx_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 objects.extend(cxx_objects)\n\n self.compiler.compiler_so[0] = old_compiler\n\n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects = 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=[])\n objects.extend(f_objects)\n\n self.compiler.create_static_lib(objects, lib_name,\n output_dir=self.build_clib,\n debug=self.debug)\n return\n", "methods": [ { "name": "get_headers", "long_name": "get_headers( directory_list )", "filename": "build_clib.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "directory_list" ], "start_line": 18, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_directories", "long_name": "get_directories( list_of_sources )", "filename": "build_clib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "list_of_sources" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_clib.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 45, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_clib.py", "nloc": 10, "complexity": 2, "token_count": 48, "parameters": [ "self" ], "start_line": 50, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "have_f_sources", "long_name": "have_f_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 65, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "have_cxx_sources", "long_name": "have_cxx_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 71, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_clib.py", "nloc": 31, "complexity": 5, "token_count": 220, "parameters": [ "self" ], "start_line": 77, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_clib.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "filenames", "dirname", "names" ], "start_line": 122, "end_line": 131, "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_clib.py", "nloc": 17, "complexity": 5, "token_count": 131, "parameters": [ "self" ], "start_line": 118, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 64, "complexity": 12, "token_count": 400, "parameters": [ "self", "libraries" ], "start_line": 145, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_headers", "long_name": "get_headers( directory_list )", "filename": "build_clib.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "directory_list" ], "start_line": 18, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_directories", "long_name": "get_directories( list_of_sources )", "filename": "build_clib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "list_of_sources" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_clib.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 45, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_clib.py", "nloc": 10, "complexity": 2, "token_count": 48, "parameters": [ "self" ], "start_line": 50, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "have_f_sources", "long_name": "have_f_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 65, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "have_cxx_sources", "long_name": "have_cxx_sources( self )", "filename": "build_clib.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 71, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_clib.py", "nloc": 31, "complexity": 5, "token_count": 220, "parameters": [ "self" ], "start_line": 77, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_clib.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 122, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_clib.py", "nloc": 17, "complexity": 5, "token_count": 131, "parameters": [ "self" ], "start_line": 118, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 64, "complexity": 12, "token_count": 400, "parameters": [ "self", "libraries" ], "start_line": 143, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_clib.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "filenames", "dirname", "names" ], "start_line": 122, "end_line": 131, "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_clib.py", "nloc": 17, "complexity": 5, "token_count": 131, "parameters": [ "self" ], "start_line": 118, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 } ], "nloc": 178, "complexity": 42, "token_count": 1139, "diff_parsed": { "added": [ " if name[-1] in \"#~\":", " continue" ], "deleted": [] } }, { "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": "@@ -315,6 +315,8 @@ def visit_func(filenames,dirname,names):\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", "added_lines": 2, "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 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 # this hack worksaround 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", "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n # this hack worksaround 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 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": 165, "complexity": 44, "token_count": 1076, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 197, "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": 313, "end_line": 322, "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": 310, "end_line": 333, "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": 335, "end_line": 346, "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": 165, "complexity": 44, "token_count": 1076, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 197, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 313, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 310, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 333, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "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": 313, "end_line": 322, "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": 310, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 } ], "nloc": 279, "complexity": 76, "token_count": 1806, "diff_parsed": { "added": [ " if name[-1] in \"~#\":", " continue" ], "deleted": [] } } ] }, { "hash": "ed27d887320f710f0af499fba1f141e1f06e1e6c", "msg": "Using /Zm1000 when compiling C++ sources with MSVC compiler.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-05T21:53:37+00:00", "author_timezone": 0, "committer_date": "2004-04-05T21:53:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "63bbe4c6aa8f95d71b86223e731eba981951c3ad" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 1, "insertions": 4, "lines": 5, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_ext.py", "new_path": "scipy_distutils/command/build_ext.py", "filename": "build_ext.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -147,7 +147,10 @@ def build_extension(self, ext):\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n- # this hack worksaround msvc compiler attributes\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", "added_lines": 4, "deleted_lines": 1, "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n 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", "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n if self.compiler.compiler_type=='msvc':\n # this hack worksaround 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": 167, "complexity": 45, "token_count": 1085, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 200, "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": 316, "end_line": 325, "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": 313, "end_line": 336, "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": 338, "end_line": 349, "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": 165, "complexity": 44, "token_count": 1076, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 197, "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": 313, "end_line": 322, "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": 310, "end_line": 333, "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": 335, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 167, "complexity": 45, "token_count": 1085, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 200, "top_nesting_level": 1 } ], "nloc": 281, "complexity": 77, "token_count": 1815, "diff_parsed": { "added": [ " if cxx_sources:", " # Needed to compile kiva.agg._agg extension.", " extra_args.append('/Zm1000')", " # this hack works around the msvc compiler attributes" ], "deleted": [ " # this hack worksaround msvc compiler attributes" ] } } ] }, { "hash": "468a2f286f3a86c984ebfe8d6b81c7ac26de5135", "msg": "Return original exe name when not found.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-09T16:33:47+00:00", "author_timezone": 0, "committer_date": "2004-04-09T16:33:47+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "ed27d887320f710f0af499fba1f141e1f06e1e6c" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 1, "insertions": 3, "lines": 4, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -123,6 +123,7 @@ def find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n+ orig_exe = exe\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n@@ -160,7 +161,8 @@ def find_executable(exe, path=None):\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n- log.warn('Could not locate executable %s' % exe)\n+ log.warn('Could not locate executable %s' % orig_exe)\n+ return orig_exe\n return exe\n \n ############################################################\n", "added_lines": 3, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n# nt | win32 | Windows XP, Python 2.3.3\n#\n# Known bugs:\n# - Tests, that send messages to stderr, fail when executed from MSYS prompt\n# because the messages are lost at some point.\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.debug('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n orig_exe = exe\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n if exe[0]=='\"':\n exe = exe[1:-1]\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % orig_exe)\n return orig_exe\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell,\n use_tee=use_tee,**env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n\n if stsfile is not None:\n f = open(stsfile,'r')\n status_text = f.read()\n status = int(status_text)\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n if use_tee is None:\n use_tee = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n\n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C'] + argv\n using_command = 1\n\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n argv0 = argv[0]\n if not using_command:\n argv[0] = quote_arg(argv0)\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n #XXX: disabled for now as it does not work from cmd under win32.\n # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # not be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n text = text + errmess\n print errmess\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n if use_tee:\n print text\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn(**kws):\n s,o = exec_command(['svn','status'],**kws)\n assert s,(s,o)\n print 'svn ok'\n\ndef test_cl(**kws):\n if os.name=='nt':\n s,o = exec_command(['cl','/V'],**kws)\n assert s,(s,o)\n print 'cl ok'\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn(use_tee=1)\n test_cl(use_tee=1)\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n# nt | win32 | Windows XP, Python 2.3.3\n#\n# Known bugs:\n# - Tests, that send messages to stderr, fail when executed from MSYS prompt\n# because the messages are lost at some point.\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.debug('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n if os.name=='posix':\n realpath = os.path.realpath\n else:\n realpath = lambda a:a\n if exe[0]=='\"':\n exe = exe[1:-1]\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = realpath(fn+s)\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n exe = realpath(exe)\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell,\n use_tee=use_tee,**env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n\n if stsfile is not None:\n f = open(stsfile,'r')\n status_text = f.read()\n status = int(status_text)\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, use_tee = None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n if use_tee is None:\n use_tee = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n\n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C'] + argv\n using_command = 1\n\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n argv0 = argv[0]\n if not using_command:\n argv[0] = quote_arg(argv0)\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n #XXX: disabled for now as it does not work from cmd under win32.\n # Tests fail on msys\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n # Not sure how to handle the case where errmess\n # contains only warning messages and that should\n # not be treated as errors.\n #status = 998\n if text:\n text = text + '\\n'\n #text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n text = text + errmess\n print errmess\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n if use_tee:\n print text\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn(**kws):\n s,o = exec_command(['svn','status'],**kws)\n assert s,(s,o)\n print 'svn ok'\n\ndef test_cl(**kws):\n if os.name=='nt':\n s,o = exec_command(['cl','/V'],**kws)\n assert s,(s,o)\n print 'cl ok'\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn(use_tee=1)\n test_cl(use_tee=1)\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 61, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 72, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 104, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 43, "complexity": 17, "token_count": 335, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 170, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 177, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 46, "complexity": 14, "token_count": 335, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 182, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 41, "complexity": 8, "token_count": 244, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 256, "end_line": 306, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 309, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 348, "end_line": 351, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 83, "complexity": 20, "token_count": 573, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 353, "end_line": 462, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 465, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 541, "end_line": 587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 589, "end_line": 605, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( ** kws )", "filename": "exec_command.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "kws" ], "start_line": 607, "end_line": 610, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_cl", "long_name": "test_cl( ** kws )", "filename": "exec_command.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "kws" ], "start_line": 612, "end_line": 616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 61, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 72, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 104, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 41, "complexity": 17, "token_count": 330, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 168, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 175, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 46, "complexity": 14, "token_count": 335, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 180, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 41, "complexity": 8, "token_count": 244, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 254, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 307, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 346, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 83, "complexity": 20, "token_count": 573, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 351, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 110, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 463, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 539, "end_line": 585, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 587, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( ** kws )", "filename": "exec_command.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "kws" ], "start_line": 605, "end_line": 608, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_cl", "long_name": "test_cl( ** kws )", "filename": "exec_command.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "kws" ], "start_line": 610, "end_line": 614, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 43, "complexity": 17, "token_count": 335, "parameters": [ "exe", "path" ], "start_line": 122, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 } ], "nloc": 444, "complexity": 139, "token_count": 3428, "diff_parsed": { "added": [ " orig_exe = exe", " log.warn('Could not locate executable %s' % orig_exe)", " return orig_exe" ], "deleted": [ " log.warn('Could not locate executable %s' % exe)" ] } } ] }, { "hash": "ec7071edc2ad615b07cbe79e4459145ca53900cd", "msg": "Implemented wx_info support.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-09T17:05:29+00:00", "author_timezone": 0, "committer_date": "2004-04-09T17:05:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "468a2f286f3a86c984ebfe8d6b81c7ac26de5135" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 2, "insertions": 63, "lines": 65, "files": 1, "dmm_unit_size": 0.14545454545454545, "dmm_unit_complexity": 0.16363636363636364, "dmm_unit_interfacing": 0.9272727272727272, "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": "@@ -23,7 +23,8 @@\n numarray_info\n boost_python\n agg2\n-\n+ wx_info\n+ \n Usage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n@@ -95,6 +96,7 @@\n from distutils.errors import DistutilsError\n from glob import glob\n import ConfigParser\n+from exec_command import find_executable, exec_command\n \n from distutils.sysconfig import get_config_vars\n \n@@ -157,6 +159,7 @@ def get_info(name,notfound_action=0):\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n+ 'wx':wx_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n \n@@ -1194,6 +1197,64 @@ def calc_info(self):\n self.set_info(**info)\n return\n \n+class wx_info(system_info):\n+ section = 'wx'\n+ config_env_var = 'WX_CONFIG'\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 'wx-config'\n+ def get_config_output(self, wx_config, option):\n+ s,o = exec_command(wx_config+' '+option,use_tee=0)\n+ if not s:\n+ return o\n+ def calc_info(self):\n+ wx_config = find_executable(self.get_config_exe())\n+ if not os.path.isfile(wx_config):\n+ print 'File not found: %s. Cannot determine wx info.' % (wx_config)\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(wx_config,'--version')\n+ if version:\n+ macros.append(('WX_VERSION','\"\\\\\"%s\\\\\"\"' % (version)))\n+ opts = self.get_config_output(wx_config,'--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(wx_config,'--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 \n ## def vstr2hex(version):\n ## bits = []\n@@ -1265,6 +1326,6 @@ def show_all():\n if __name__ == \"__main__\":\n show_all()\n if 0:\n- c = lapack_opt_info()\n+ c = wx_info()\n c.verbosity = 2\n c.get_info()\n", "added_lines": 63, "deleted_lines": 2, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n wx_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\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 }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(system_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\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 'wx-config'\n def get_config_output(self, wx_config, option):\n s,o = exec_command(wx_config+' '+option,use_tee=0)\n if not s:\n return o\n def calc_info(self):\n wx_config = find_executable(self.get_config_exe())\n if not os.path.isfile(wx_config):\n print 'File not found: %s. Cannot determine wx info.' % (wx_config)\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(wx_config,'--version')\n if version:\n macros.append(('WX_VERSION','\"\\\\\"%s\\\\\"\"' % (version)))\n opts = self.get_config_output(wx_config,'--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(wx_config,'--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\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 = wx_info()\n c.verbosity = 2\n c.get_info()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = lapack_opt_info()\n c.verbosity = 2\n c.get_info()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 28, "complexity": 1, "token_count": 134, "parameters": [ "name", "notfound_action" ], "start_line": 131, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 244, "end_line": 268, "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": 270, "end_line": 271, "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": 273, "end_line": 274, "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": 276, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 313, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "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": 340, "end_line": 341, "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": 343, "end_line": 344, "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": 346, "end_line": 351, "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": 353, "end_line": 364, "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": 366, "end_line": 374, "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": 376, "end_line": 378, "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": 380, "end_line": 389, "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": 391, "end_line": 392, "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": 402, "end_line": 403, "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": 405, "end_line": 430, "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": 472, "end_line": 477, "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": 479, "end_line": 499, "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": 508, "end_line": 514, "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": 516, "end_line": 595, "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": 600, "end_line": 628, "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": 648, "end_line": 660, "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": 667, "end_line": 672, "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": 674, "end_line": 758, "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": 781, "end_line": 790, "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": 777, "end_line": 830, "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": 835, "end_line": 909, "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": 914, "end_line": 967, "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": 976, "end_line": 988, "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": 996, "end_line": 1001, "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": 1003, "end_line": 1038, "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": 1044, "end_line": 1047, "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": 1049, "end_line": 1068, "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": 1075, "end_line": 1096, "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": 1098, "end_line": 1126, "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": 1136, "end_line": 1141, "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": 1143, "end_line": 1163, "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": 1169, "end_line": 1174, "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": 1176, "end_line": 1198, "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": 28, "parameters": [ "self" ], "start_line": 1204, "end_line": 1207, "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 , wx_config , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "wx_config", "option" ], "start_line": 1208, "end_line": 1211, "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": 46, "complexity": 19, "token_count": 336, "parameters": [ "self" ], "start_line": 1212, "end_line": 1257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "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": 1270, "end_line": 1294, "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": 1298, "end_line": 1314, "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": 1316, "end_line": 1324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 27, "complexity": 1, "token_count": 130, "parameters": [ "name", "notfound_action" ], "start_line": 129, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 241, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 267, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 270, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 273, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 310, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 340, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 377, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 388, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 399, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 402, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 469, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 476, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 513, "end_line": 592, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 597, "end_line": 625, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 645, "end_line": 657, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 664, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 671, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 44, "complexity": 9, "token_count": 280, "parameters": [ "config" ], "start_line": 774, "end_line": 827, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 832, "end_line": 906, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 911, "end_line": 964, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 973, "end_line": 985, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 993, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1000, "end_line": 1035, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1041, "end_line": 1044, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1046, "end_line": 1065, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1072, "end_line": 1093, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1095, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1133, "end_line": 1138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1140, "end_line": 1160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1166, "end_line": 1171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1173, "end_line": 1195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1209, "end_line": 1233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1237, "end_line": 1253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1255, "end_line": 1263, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_config_output", "long_name": "get_config_output( self , wx_config , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "wx_config", "option" ], "start_line": 1208, "end_line": 1211, "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": 46, "complexity": 19, "token_count": 336, "parameters": [ "self" ], "start_line": 1212, "end_line": 1257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "get_config_exe", "long_name": "get_config_exe( self )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 1204, "end_line": 1207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 28, "complexity": 1, "token_count": 134, "parameters": [ "name", "notfound_action" ], "start_line": 131, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 } ], "nloc": 1172, "complexity": 257, "token_count": 6585, "diff_parsed": { "added": [ " wx_info", "", "from exec_command import find_executable, exec_command", " 'wx':wx_info,", "class wx_info(system_info):", " section = 'wx'", " config_env_var = 'WX_CONFIG'", "", " def get_config_exe(self):", " if os.environ.has_key(self.config_env_var):", " return os.environ[self.config_env_var]", " return 'wx-config'", " def get_config_output(self, wx_config, option):", " s,o = exec_command(wx_config+' '+option,use_tee=0)", " if not s:", " return o", " def calc_info(self):", " wx_config = find_executable(self.get_config_exe())", " if not os.path.isfile(wx_config):", " print 'File not found: %s. Cannot determine wx info.' % (wx_config)", " return", " info = {}", " macros = []", " libraries = []", " library_dirs = []", " include_dirs = []", " extra_link_args = []", " extra_compile_args = []", " version = self.get_config_output(wx_config,'--version')", " if version:", " macros.append(('WX_VERSION','\"\\\\\"%s\\\\\"\"' % (version)))", " opts = self.get_config_output(wx_config,'--libs')", " if opts:", " for opt in opts.split():", " if opt[:2]=='-l':", " libraries.append(opt[2:])", " elif opt[:2]=='-L':", " library_dirs.append(opt[2:])", " else:", " extra_link_args.append(opt)", " opts = self.get_config_output(wx_config,'--cxxflags')", " if opts:", " for opt in opts.split():", " if opt[:2]=='-I':", " include_dirs.append(opt[2:])", " elif opt[:2]=='-D':", " if '=' in opt:", " n,v = opt[2:].split('=')", " macros.append((n,v))", " else:", " macros.append((opt[2:],None))", " else:", " extra_compile_args.append(opt)", " if macros: dict_append(info, define_macros = macros)", " if libraries: dict_append(info, libraries = libraries)", " if library_dirs: dict_append(info, library_dirs = library_dirs)", " if include_dirs: dict_append(info, include_dirs = include_dirs)", " if extra_link_args: dict_append(info, extra_link_args = extra_link_args)", " if extra_compile_args: dict_append(info, extra_compile_args = extra_compile_args)", " if info:", " self.set_info(**info)", " return", " c = wx_info()" ], "deleted": [ "", " c = lapack_opt_info()" ] } } ] }, { "hash": "a1f50a2bf210c590095b4b7a2a2d5f30f6cba615", "msg": "Added WX_RELEASE_, WX_VERSION_ macros to wx_info, changed WX_VERSION to WX_INFO.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-09T19:40:28+00:00", "author_timezone": 0, "committer_date": "2004-04-09T19:40:28+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "ec7071edc2ad615b07cbe79e4459145ca53900cd" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 1, "insertions": 5, "lines": 6, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1223,7 +1223,11 @@ def calc_info(self):\n extra_compile_args = []\n version = self.get_config_output(wx_config,'--version')\n if version:\n- macros.append(('WX_VERSION','\"\\\\\"%s\\\\\"\"' % (version)))\n+ macros.append(('WX_INFO','\"\\\\\"%s\\\\\"\"' % (version)))\n+ macros.append(('WX_VERSION_%s' % (version.replace('.','_')),None))\n+ release = self.get_config_output(wx_config,'--release')\n+ if release:\n+ macros.append(('WX_RELEASE_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(wx_config,'--libs')\n if opts:\n for opt in opts.split():\n", "added_lines": 5, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n wx_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\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 }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(system_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\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 'wx-config'\n def get_config_output(self, wx_config, option):\n s,o = exec_command(wx_config+' '+option,use_tee=0)\n if not s:\n return o\n def calc_info(self):\n wx_config = find_executable(self.get_config_exe())\n if not os.path.isfile(wx_config):\n print 'File not found: %s. Cannot determine wx info.' % (wx_config)\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(wx_config,'--version')\n if version:\n macros.append(('WX_INFO','\"\\\\\"%s\\\\\"\"' % (version)))\n macros.append(('WX_VERSION_%s' % (version.replace('.','_')),None))\n release = self.get_config_output(wx_config,'--release')\n if release:\n macros.append(('WX_RELEASE_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(wx_config,'--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(wx_config,'--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\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 = wx_info()\n c.verbosity = 2\n c.get_info()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n wx_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\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 }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(system_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\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 'wx-config'\n def get_config_output(self, wx_config, option):\n s,o = exec_command(wx_config+' '+option,use_tee=0)\n if not s:\n return o\n def calc_info(self):\n wx_config = find_executable(self.get_config_exe())\n if not os.path.isfile(wx_config):\n print 'File not found: %s. Cannot determine wx info.' % (wx_config)\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(wx_config,'--version')\n if version:\n macros.append(('WX_VERSION','\"\\\\\"%s\\\\\"\"' % (version)))\n opts = self.get_config_output(wx_config,'--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(wx_config,'--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\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 = wx_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": 28, "complexity": 1, "token_count": 134, "parameters": [ "name", "notfound_action" ], "start_line": 131, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 244, "end_line": 268, "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": 270, "end_line": 271, "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": 273, "end_line": 274, "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": 276, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 313, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "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": 340, "end_line": 341, "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": 343, "end_line": 344, "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": 346, "end_line": 351, "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": 353, "end_line": 364, "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": 366, "end_line": 374, "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": 376, "end_line": 378, "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": 380, "end_line": 389, "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": 391, "end_line": 392, "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": 402, "end_line": 403, "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": 405, "end_line": 430, "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": 472, "end_line": 477, "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": 479, "end_line": 499, "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": 508, "end_line": 514, "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": 516, "end_line": 595, "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": 600, "end_line": 628, "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": 648, "end_line": 660, "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": 667, "end_line": 672, "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": 674, "end_line": 758, "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": 781, "end_line": 790, "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": 777, "end_line": 830, "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": 835, "end_line": 909, "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": 914, "end_line": 967, "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": 976, "end_line": 988, "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": 996, "end_line": 1001, "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": 1003, "end_line": 1038, "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": 1044, "end_line": 1047, "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": 1049, "end_line": 1068, "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": 1075, "end_line": 1096, "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": 1098, "end_line": 1126, "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": 1136, "end_line": 1141, "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": 1143, "end_line": 1163, "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": 1169, "end_line": 1174, "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": 1176, "end_line": 1198, "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": 28, "parameters": [ "self" ], "start_line": 1204, "end_line": 1207, "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 , wx_config , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "wx_config", "option" ], "start_line": 1208, "end_line": 1211, "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": 50, "complexity": 20, "token_count": 391, "parameters": [ "self" ], "start_line": 1212, "end_line": 1261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 1274, "end_line": 1298, "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": 1302, "end_line": 1318, "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": 1320, "end_line": 1328, "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": 28, "complexity": 1, "token_count": 134, "parameters": [ "name", "notfound_action" ], "start_line": 131, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 244, "end_line": 268, "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": 270, "end_line": 271, "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": 273, "end_line": 274, "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": 276, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 313, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "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": 340, "end_line": 341, "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": 343, "end_line": 344, "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": 346, "end_line": 351, "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": 353, "end_line": 364, "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": 366, "end_line": 374, "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": 376, "end_line": 378, "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": 380, "end_line": 389, "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": 391, "end_line": 392, "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": 402, "end_line": 403, "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": 405, "end_line": 430, "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": 472, "end_line": 477, "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": 479, "end_line": 499, "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": 508, "end_line": 514, "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": 516, "end_line": 595, "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": 600, "end_line": 628, "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": 648, "end_line": 660, "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": 667, "end_line": 672, "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": 674, "end_line": 758, "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": 781, "end_line": 790, "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": 777, "end_line": 830, "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": 835, "end_line": 909, "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": 914, "end_line": 967, "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": 976, "end_line": 988, "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": 996, "end_line": 1001, "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": 1003, "end_line": 1038, "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": 1044, "end_line": 1047, "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": 1049, "end_line": 1068, "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": 1075, "end_line": 1096, "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": 1098, "end_line": 1126, "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": 1136, "end_line": 1141, "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": 1143, "end_line": 1163, "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": 1169, "end_line": 1174, "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": 1176, "end_line": 1198, "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": 28, "parameters": [ "self" ], "start_line": 1204, "end_line": 1207, "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 , wx_config , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "wx_config", "option" ], "start_line": 1208, "end_line": 1211, "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": 46, "complexity": 19, "token_count": 336, "parameters": [ "self" ], "start_line": 1212, "end_line": 1257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "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": 1270, "end_line": 1294, "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": 1298, "end_line": 1314, "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": 1316, "end_line": 1324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 20, "token_count": 391, "parameters": [ "self" ], "start_line": 1212, "end_line": 1261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "top_nesting_level": 1 } ], "nloc": 1176, "complexity": 258, "token_count": 6640, "diff_parsed": { "added": [ " macros.append(('WX_INFO','\"\\\\\"%s\\\\\"\"' % (version)))", " macros.append(('WX_VERSION_%s' % (version.replace('.','_')),None))", " release = self.get_config_output(wx_config,'--release')", " if release:", " macros.append(('WX_RELEASE_%s' % (release.replace('.','_')),None))" ], "deleted": [ " macros.append(('WX_VERSION','\"\\\\\"%s\\\\\"\"' % (version)))" ] } } ] }, { "hash": "e1802e7551ce13ba85d43c7048c52f2920174a4d", "msg": "Added number of new info classes.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-04-10T15:49:48+00:00", "author_timezone": 0, "committer_date": "2004-04-10T15:49:48+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "a1f50a2bf210c590095b4b7a2a2d5f30f6cba615" ], "project_name": "repo_copy", "project_path": "/tmp/tmpsnsbmj1v/repo_copy", "deletions": 19, "insertions": 93, "lines": 112, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.75, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -24,7 +24,14 @@\n boost_python\n agg2\n wx_info\n- \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+\n Usage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n@@ -160,6 +167,18 @@ def get_info(name,notfound_action=0):\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 \n@@ -1197,22 +1216,29 @@ def calc_info(self):\n self.set_info(**info)\n return\n \n-class wx_info(system_info):\n- section = 'wx'\n- config_env_var = 'WX_CONFIG'\n+class _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 'wx-config'\n- def get_config_output(self, wx_config, option):\n- s,o = exec_command(wx_config+' '+option,use_tee=0)\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- wx_config = find_executable(self.get_config_exe())\n- if not os.path.isfile(wx_config):\n- print 'File not found: %s. Cannot determine wx info.' % (wx_config)\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@@ -1221,14 +1247,17 @@ def calc_info(self):\n include_dirs = []\n extra_link_args = []\n extra_compile_args = []\n- version = self.get_config_output(wx_config,'--version')\n+ version = self.get_config_output(config_exe,self.version_flag)\n if version:\n- macros.append(('WX_INFO','\"\\\\\"%s\\\\\"\"' % (version)))\n- macros.append(('WX_VERSION_%s' % (version.replace('.','_')),None))\n- release = self.get_config_output(wx_config,'--release')\n- if release:\n- macros.append(('WX_RELEASE_%s' % (release.replace('.','_')),None))\n- opts = self.get_config_output(wx_config,'--libs')\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@@ -1237,7 +1266,7 @@ def calc_info(self):\n library_dirs.append(opt[2:])\n else:\n extra_link_args.append(opt)\n- opts = self.get_config_output(wx_config,'--cxxflags')\n+ opts = self.get_config_output(config_exe,'--cxxflags')\n if opts:\n for opt in opts.split():\n if opt[:2]=='-I':\n@@ -1260,6 +1289,51 @@ def calc_info(self):\n self.set_info(**info)\n return\n \n+class 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+\n+class 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+\n+class 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+\n+class 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+\n+class 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+\n+class gtkp_2_info(_pkg_config_info):\n+ section = 'gtkp_2'\n+ append_config_exe = 'gtk+-2.0'\n+ version_macro_name = 'GTK_VERSION'\n+\n+class xft_info(_pkg_config_info):\n+ section = 'xft'\n+ append_config_exe = 'xft'\n+ version_macro_name = 'XFT_VERSION'\n+\n+class 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@@ -1330,6 +1404,6 @@ def show_all():\n if __name__ == \"__main__\":\n show_all()\n if 0:\n- c = wx_info()\n+ c = gdk_pixbuf_2_info()\n c.verbosity = 2\n c.get_info()\n", "added_lines": 93, "deleted_lines": 19, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n 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\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 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", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n wx_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\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 }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\nclass wx_info(system_info):\n section = 'wx'\n config_env_var = 'WX_CONFIG'\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 'wx-config'\n def get_config_output(self, wx_config, option):\n s,o = exec_command(wx_config+' '+option,use_tee=0)\n if not s:\n return o\n def calc_info(self):\n wx_config = find_executable(self.get_config_exe())\n if not os.path.isfile(wx_config):\n print 'File not found: %s. Cannot determine wx info.' % (wx_config)\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(wx_config,'--version')\n if version:\n macros.append(('WX_INFO','\"\\\\\"%s\\\\\"\"' % (version)))\n macros.append(('WX_VERSION_%s' % (version.replace('.','_')),None))\n release = self.get_config_output(wx_config,'--release')\n if release:\n macros.append(('WX_RELEASE_%s' % (release.replace('.','_')),None))\n opts = self.get_config_output(wx_config,'--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(wx_config,'--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\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 = wx_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": 138, "end_line": 183, "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": 263, "end_line": 287, "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": 289, "end_line": 290, "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": 292, "end_line": 293, "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": 295, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 332, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 356, "end_line": 357, "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": 359, "end_line": 360, "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": 362, "end_line": 363, "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": 365, "end_line": 370, "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": 372, "end_line": 383, "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": 385, "end_line": 393, "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": 395, "end_line": 397, "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": 399, "end_line": 408, "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": 410, "end_line": 411, "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": 421, "end_line": 422, "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": 424, "end_line": 449, "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": 491, "end_line": 496, "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": 498, "end_line": 518, "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": 527, "end_line": 533, "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": 535, "end_line": 614, "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": 619, "end_line": 647, "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": 667, "end_line": 679, "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": 686, "end_line": 691, "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": 693, "end_line": 777, "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": 800, "end_line": 809, "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": 796, "end_line": 849, "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": 854, "end_line": 928, "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": 933, "end_line": 986, "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": 995, "end_line": 1007, "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": 1015, "end_line": 1020, "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": 1022, "end_line": 1057, "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": 1063, "end_line": 1066, "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": 1068, "end_line": 1087, "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": 1094, "end_line": 1115, "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": 1117, "end_line": 1145, "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": 1155, "end_line": 1160, "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": 1162, "end_line": 1182, "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": 1188, "end_line": 1193, "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": 1195, "end_line": 1217, "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": 1228, "end_line": 1231, "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": 1232, "end_line": 1235, "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": 1237, "end_line": 1290, "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": 1348, "end_line": 1372, "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": 1376, "end_line": 1392, "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": 1394, "end_line": 1402, "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": 28, "complexity": 1, "token_count": 134, "parameters": [ "name", "notfound_action" ], "start_line": 131, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 244, "end_line": 268, "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": 270, "end_line": 271, "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": 273, "end_line": 274, "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": 276, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 313, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "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": 340, "end_line": 341, "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": 343, "end_line": 344, "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": 346, "end_line": 351, "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": 353, "end_line": 364, "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": 366, "end_line": 374, "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": 376, "end_line": 378, "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": 380, "end_line": 389, "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": 391, "end_line": 392, "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": 402, "end_line": 403, "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": 405, "end_line": 430, "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": 472, "end_line": 477, "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": 479, "end_line": 499, "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": 508, "end_line": 514, "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": 516, "end_line": 595, "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": 600, "end_line": 628, "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": 648, "end_line": 660, "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": 667, "end_line": 672, "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": 674, "end_line": 758, "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": 781, "end_line": 790, "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": 777, "end_line": 830, "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": 835, "end_line": 909, "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": 914, "end_line": 967, "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": 976, "end_line": 988, "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": 996, "end_line": 1001, "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": 1003, "end_line": 1038, "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": 1044, "end_line": 1047, "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": 1049, "end_line": 1068, "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": 1075, "end_line": 1096, "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": 1098, "end_line": 1126, "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": 1136, "end_line": 1141, "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": 1143, "end_line": 1163, "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": 1169, "end_line": 1174, "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": 1176, "end_line": 1198, "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": 28, "parameters": [ "self" ], "start_line": 1204, "end_line": 1207, "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 , wx_config , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "wx_config", "option" ], "start_line": 1208, "end_line": 1211, "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": 50, "complexity": 20, "token_count": 391, "parameters": [ "self" ], "start_line": 1212, "end_line": 1261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 50, "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": 1274, "end_line": 1298, "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": 1302, "end_line": 1318, "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": 1320, "end_line": 1328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "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": 1228, "end_line": 1231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "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": 138, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 }, { "name": "get_config_output", "long_name": "get_config_output( self , wx_config , option )", "filename": "system_info.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "wx_config", "option" ], "start_line": 1208, "end_line": 1211, "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": 1237, "end_line": 1290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "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": 1232, "end_line": 1235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 } ], "nloc": 1240, "complexity": 260, "token_count": 6885, "diff_parsed": { "added": [ " gdk_pixbuf_xlib_2_info", " gdk_pixbuf_2_info", " gdk_x11_2_info", " gtkp_x11_2_info", " gtkp_2_info", " xft_info", " freetype2_info", "", " 'gdk_pixbuf_xlib_2':gdk_pixbuf_xlib_2_info,", " 'gdk-pixbuf-xlib-2.0':gdk_pixbuf_xlib_2_info,", " 'gdk_pixbuf_2':gdk_pixbuf_2_info,", " 'gdk-pixbuf-2.0':gdk_pixbuf_2_info,", " 'gdk_x11_2':gdk_x11_2_info,", " 'gdk-x11-2.0':gdk_x11_2_info,", " 'gtkp_x11_2':gtkp_x11_2_info,", " 'gtk+-x11-2.0':gtkp_x11_2_info,", " 'gtkp_2':gtkp_2_info,", " 'gtk+-2.0':gtkp_2_info,", " 'xft':xft_info,", " 'freetype2':freetype2_info,", "class _pkg_config_info(system_info):", " section = None", " config_env_var = 'PKG_CONFIG'", " default_config_exe = 'pkg-config'", " append_config_exe = ''", " version_macro_name = None", " release_macro_name = None", " version_flag = '--modversion'", " return self.default_config_exe", " def get_config_output(self, config_exe, option):", " s,o = exec_command(config_exe+' '+self.append_config_exe+' '+option,use_tee=0)", "", " config_exe = find_executable(self.get_config_exe())", " if not os.path.isfile(config_exe):", " print 'File not found: %s. Cannot determine %s info.' \\", " % (config_exe, self.section)", " version = self.get_config_output(config_exe,self.version_flag)", " macros.append((self.__class__.__name__.split('.')[-1].upper(),", " '\"\\\\\"%s\\\\\"\"' % (version)))", " if self.version_macro_name:", " macros.append((self.version_macro_name+'_%s' % (version.replace('.','_')),None))", " if self.release_macro_name:", " release = self.get_config_output(config_exe,'--release')", " if release:", " macros.append((self.release_macro_name+'_%s' % (release.replace('.','_')),None))", " opts = self.get_config_output(config_exe,'--libs')", " opts = self.get_config_output(config_exe,'--cxxflags')", "class wx_info(_pkg_config_info):", " section = 'wx'", " config_env_var = 'WX_CONFIG'", " default_config_exe = 'wx-config'", " append_config_exe = ''", " version_macro_name = 'WX_VERSION'", " release_macro_name = 'WX_RELEASE'", " version_flag = '--version'", "", "class gdk_pixbuf_xlib_2_info(_pkg_config_info):", " section = 'gdk_pixbuf_xlib_2'", " append_config_exe = 'gdk-pixbuf-xlib-2.0'", " version_macro_name = 'GDK_PIXBUF_XLIB_VERSION'", "", "class gdk_pixbuf_2_info(_pkg_config_info):", " section = 'gdk_pixbuf_2'", " append_config_exe = 'gdk-pixbuf-2.0'", " version_macro_name = 'GDK_PIXBUF_VERSION'", "", "class gdk_x11_2_info(_pkg_config_info):", " section = 'gdk_x11_2'", " append_config_exe = 'gdk-x11-2.0'", " version_macro_name = 'GDK_X11_VERSION'", "", "class gtkp_x11_2_info(_pkg_config_info):", " section = 'gtkp_x11_2'", " append_config_exe = 'gtk+-x11-2.0'", " version_macro_name = 'GTK_X11_VERSION'", "", "", "class gtkp_2_info(_pkg_config_info):", " section = 'gtkp_2'", " append_config_exe = 'gtk+-2.0'", " version_macro_name = 'GTK_VERSION'", "", "class xft_info(_pkg_config_info):", " section = 'xft'", " append_config_exe = 'xft'", " version_macro_name = 'XFT_VERSION'", "", "class freetype2_info(_pkg_config_info):", " section = 'freetype2'", " append_config_exe = 'freetype2'", " version_macro_name = 'FREETYPE2_VERSION'", "", " c = gdk_pixbuf_2_info()" ], "deleted": [ "", "class wx_info(system_info):", " section = 'wx'", " config_env_var = 'WX_CONFIG'", " return 'wx-config'", " def get_config_output(self, wx_config, option):", " s,o = exec_command(wx_config+' '+option,use_tee=0)", " wx_config = find_executable(self.get_config_exe())", " if not os.path.isfile(wx_config):", " print 'File not found: %s. Cannot determine wx info.' % (wx_config)", " version = self.get_config_output(wx_config,'--version')", " macros.append(('WX_INFO','\"\\\\\"%s\\\\\"\"' % (version)))", " macros.append(('WX_VERSION_%s' % (version.replace('.','_')),None))", " release = self.get_config_output(wx_config,'--release')", " if release:", " macros.append(('WX_RELEASE_%s' % (release.replace('.','_')),None))", " opts = self.get_config_output(wx_config,'--libs')", " opts = self.get_config_output(wx_config,'--cxxflags')", " c = wx_info()" ] } } ] } ]