[Pydev-cvs] org.python.pydev.jython/src/org/python/pydev/jython JythonPlugin.java, 1.18, 1.19
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2006-09-12 00:15:59
|
Update of /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13583/src/org/python/pydev/jython Modified Files: JythonPlugin.java Log Message: Changes for running the tests (by Darrell) Index: JythonPlugin.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython/JythonPlugin.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** JythonPlugin.java 7 Jun 2006 21:54:41 -0000 1.18 --- JythonPlugin.java 12 Sep 2006 00:15:57 -0000 1.19 *************** *** 40,43 **** --- 40,73 ---- private static final boolean DEBUG = false; + public static boolean DEBUG_RELOAD = true; + + /** + * While in tests, errors are thrown even if we don't have a shared instance for JythonPlugin + */ + public static boolean IN_TESTS = false; + + private static String LOAD_FILE_SCRIPT = "" + + "print '---> reloading', r'%s'\n" + + "import sys \n" + //sys will always be on the namespace (so that we can set sys.path) + "f = open(r'%s') \n" + + "try: \n" + + " toExec = f.read() \n" + + "finally: \n" + + " f.close() \n" + + "%s \n" + //space to put the needed folders on sys.path + ""; + + public static synchronized void setDebugReload(boolean b){ + if(b != DEBUG_RELOAD){ + if(b == false){ + LOAD_FILE_SCRIPT = "#"+LOAD_FILE_SCRIPT; + //System.out.println(">>"+LOAD_FILE_SCRIPT+"<<"); + }else{ + LOAD_FILE_SCRIPT = LOAD_FILE_SCRIPT.substring(1); + //System.out.println(">>"+LOAD_FILE_SCRIPT+"<<"); + } + DEBUG_RELOAD = b; + } + } // ----------------- SINGLETON THINGS ----------------------------- *************** *** 262,266 **** if(file != null){ if(!file.exists()){ ! Log.log(IStatus.ERROR, "The folder:"+file+" does not exist and therefore cannot be used to find scripts to run starting with:"+startingWith, null); } File[] files = getFilesBeneathFolder(startingWith, file); --- 292,299 ---- if(file != null){ if(!file.exists()){ ! String msg = "The folder:"+file+" does not exist and therefore cannot be used to " + ! "find scripts to run starting with:"+startingWith; ! Log.log(IStatus.ERROR, msg, null); ! errors.add(new RuntimeException(msg)); } File[] files = getFilesBeneathFolder(startingWith, file); *************** *** 284,288 **** public boolean accept(File pathname) { ! if(pathname.getName().startsWith(startingWith)){ return true; } --- 317,322 ---- public boolean accept(File pathname) { ! String name = pathname.getName(); ! if(name.startsWith(startingWith) && name.endsWith(".py")){ return true; } *************** *** 314,318 **** String fileName = fileToExec.getName(); if(!fileName.endsWith(".py")){ ! throw new RuntimeException("The script to be executed must be a python file."); } String codeObjName = "code"+fileName.substring(0, fileName.indexOf('.')); --- 348,352 ---- String fileName = fileToExec.getName(); if(!fileName.endsWith(".py")){ ! throw new RuntimeException("The script to be executed must be a python file. Name:"+fileName); } String codeObjName = "code"+fileName.substring(0, fileName.indexOf('.')); *************** *** 349,373 **** } String path = REF.getFileAbsolutePath(fileToExec); - String loadFile = "" + - "print '---> reloading', r'%s'\n" + - "import sys \n" + //sys will always be on the namespace (so that we can set sys.path) - "f = open(r'%s') \n" + - "try: \n" + - " toExec = f.read() \n" + - "finally: \n" + - " f.close() \n" + - "%s \n" + //space to put the needed folders on sys.path - ""; ! StringBuffer pythonPathFolders = new StringBuffer(); ! pythonPathFolders.append("["); for (File file : pythonpathFolders) { if (file != null){ ! pythonPathFolders.append("r'"); ! pythonPathFolders.append(REF.getFileAbsolutePath(file)); ! pythonPathFolders.append("',"); } } ! pythonPathFolders.append("]"); StringBuffer addToSysPath = new StringBuffer(); --- 383,397 ---- } String path = REF.getFileAbsolutePath(fileToExec); ! StringBuffer strPythonPathFolders = new StringBuffer(); ! strPythonPathFolders.append("["); for (File file : pythonpathFolders) { if (file != null){ ! strPythonPathFolders.append("r'"); ! strPythonPathFolders.append(REF.getFileAbsolutePath(file)); ! strPythonPathFolders.append("',"); } } ! strPythonPathFolders.append("]"); StringBuffer addToSysPath = new StringBuffer(); *************** *** 375,390 **** //we will only add the paths to the pythonpath if it was still not set or if it changed (but it will never remove the ones added before). addToSysPath.append("if not hasattr(sys, 'PYDEV_PYTHONPATH_SET') or sys.PYDEV_PYTHONPATH_SET != "); //we have to put that in sys because it is the same across different interpreters ! addToSysPath.append(pythonPathFolders); addToSysPath.append(":\n"); addToSysPath.append(" sys.PYDEV_PYTHONPATH_SET = "); ! addToSysPath.append(pythonPathFolders); addToSysPath.append("\n"); addToSysPath.append(" sys.path += "); ! addToSysPath.append(pythonPathFolders); addToSysPath.append("\n"); ! String toExec = StringUtils.format(loadFile, path, path, addToSysPath.toString()); interpreter.exec(toExec); String exec = StringUtils.format("%s = compile(toExec, r'%s', 'exec')", codeObjName, path); --- 399,414 ---- //we will only add the paths to the pythonpath if it was still not set or if it changed (but it will never remove the ones added before). addToSysPath.append("if not hasattr(sys, 'PYDEV_PYTHONPATH_SET') or sys.PYDEV_PYTHONPATH_SET != "); //we have to put that in sys because it is the same across different interpreters ! addToSysPath.append(strPythonPathFolders); addToSysPath.append(":\n"); addToSysPath.append(" sys.PYDEV_PYTHONPATH_SET = "); ! addToSysPath.append(strPythonPathFolders); addToSysPath.append("\n"); addToSysPath.append(" sys.path += "); ! addToSysPath.append(strPythonPathFolders); addToSysPath.append("\n"); ! String toExec = StringUtils.format(LOAD_FILE_SCRIPT, path, path, addToSysPath.toString()); interpreter.exec(toExec); String exec = StringUtils.format("%s = compile(toExec, r'%s', 'exec')", codeObjName, path); *************** *** 399,403 **** interpreter.exec(StringUtils.format("exec(%s)" , codeObjName)); } catch (Throwable e) { ! if(JythonPlugin.getDefault() == null){ //it is already disposed return null; --- 423,427 ---- interpreter.exec(StringUtils.format("exec(%s)" , codeObjName)); } catch (Throwable e) { ! if(!IN_TESTS && JythonPlugin.getDefault() == null){ //it is already disposed return null; |