📄 numpy.py
字号:
#!/usr/bin/env pythonimport os, sysimport commandsfrom os.path import sep, join, dirname, abspathfrom commonPkgConfigUtils import *# FIXME: script fails when running in the same folder as it is locateddef trickPythonpath(): # play tricks with pythonpath to avoid mixing up # the real numpy with this file. file_abspath = abspath(dirname(__file__)) try: splitpythonpath = os.environ['PYTHONPATH'].split(os.pathsep) index_filepath = splitpythonpath.index(file_abspath) del(splitpythonpath[index_filepath]) os.environ['PYTHONPATH'] = os.path.pathsep.join(splitpythonpath) except: passdef restorePythonpath(): file_abspath = abspath(dirname(__file__)) splitpythonpath = os.environ['PYTHONPATH'].split(os.pathsep) index_filepath = splitpythonpath.index(file_abspath) splitpythonpath.insert(index_filepath,file_abspath) os.environ['PYTHONPATH'] = os.path.pathsep.join(splitpythonpath)def pkgVersion(**kwargs): #trickPythonpath() cmdstr = "%s -c 'import numpy; print numpy.__version__'" % sys.executable failure, cmdoutput = commands.getstatusoutput(cmdstr) if failure: msg = "Unable to get numpy version.\nCommand was:\n%s" % cmdstr raise UnableToXXXException(msg, errormsg=cmdoutput) else: version = cmdoutput #restorePythonpath() return versiondef pkgCflags(**kwargs): #trickPythonpath() cmdstr = "%s -c 'import numpy; print numpy.get_include()'" % sys.executable failure, cmdoutput = commands.getstatusoutput(cmdstr) if failure: msg = "Unable to get numpy include folder.\nCommand was:\n%s" % cmdstr raise UnableToXXXException(msg, errormsg=cmdoutput) else: include_dir = cmdoutput #restorePythonpath() return "-I%s" % include_dirdef pkgLibs(**kwargs): return ""def pkgTests(version=None, cflags=None, libs=None, **kwargs): if not cflags: cflags = pkgCflags() if not version: version = pkgVersion() if not libs: libs = pkgLibs() return version, libs, cflagsdef generatePkgConf(directory=suitablePkgConfDir(), sconsEnv=None, **kwargs): # Generate a pkg-config file for numpy, put it in the given # directory, if no directory is given, a suitable location is found # using the functionality from commonPkgConfigUtils. version, libs, cflags = pkgTests(sconsEnv=sconsEnv) major_version = version.split('.')[0] """Construct the content of the pkg-configfile""" pkg = """Name: NumPyDescription: Numerical PythonVersion: %sLibs: %sCflags: %s""" % (version, libs, cflags) """Write the content to file, using correct version number""" file = open(os.path.join(directory,"numpy-%s.pc" % major_version), "w") file.write(pkg) file.close() print "done\n Found NumPy and generated pkg-config file in \n '%s'" % directoryif __name__ == "__main__": generatePkgConf(directory=".")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -