use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class CodeCompletionTestsBase method setInterpreterManager.
/**
* Sets the interpreter manager we should use
* @param path
*/
protected void setInterpreterManager(String path) {
PythonInterpreterManager interpreterManager = new PythonInterpreterManager(this.getPreferences());
InterpreterInfo info;
if (isPython3Test()) {
info = (InterpreterInfo) interpreterManager.createInterpreterInfo(TestDependent.PYTHON_30_EXE, new NullProgressMonitor(), false);
TestDependent.PYTHON_30_EXE = info.executableOrJar;
} else {
info = (InterpreterInfo) interpreterManager.createInterpreterInfo(TestDependent.PYTHON2_EXE, new NullProgressMonitor(), false);
TestDependent.PYTHON2_EXE = info.executableOrJar;
}
if (path != null) {
info = new InterpreterInfo(info.getVersion(), info.executableOrJar, PythonPathHelper.parsePythonPathFromStr(path, new ArrayList<String>()));
}
interpreterManager.setInfos(new IInterpreterInfo[] { info }, null, null);
InterpreterManagersAPI.setPythonInterpreterManager(interpreterManager);
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class IronpythonInterpreterManagerStub method getInterpreterInfos.
@Override
public IInterpreterInfo[] getInterpreterInfos() {
String defaultInterpreter = getDefaultInterpreter();
InterpreterInfo info = (InterpreterInfo) this.createInterpreterInfo(defaultInterpreter, new NullProgressMonitor(), false);
if (!InterpreterInfo.isJythonExecutable(defaultInterpreter)) {
TestDependent.IRONPYTHON_EXE = info.executableOrJar;
}
return new IInterpreterInfo[] { info };
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class PythonInterpreterManagerStub method getInterpreterInfos.
@Override
public IInterpreterInfo[] getInterpreterInfos() {
String defaultInterpreter = getDefaultInterpreter();
InterpreterInfo info = (InterpreterInfo) this.createInterpreterInfo(defaultInterpreter, new NullProgressMonitor(), false);
if (!InterpreterInfo.isJythonExecutable(defaultInterpreter) && !InterpreterInfo.isIronpythonExecutable(defaultInterpreter)) {
TestDependent.PYTHON2_EXE = info.executableOrJar;
}
return new IInterpreterInfo[] { info };
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class SyncSystemModulesManager method computeChanges.
/**
* Given the tree structure we created initially with all the changes (root) and the elements
* that the user selected in the tree (selectElements), return a list of infos updated with the
* proper pythonpath.
*/
private List<IInterpreterInfo> computeChanges(final DataAndImageTreeNode root, List<TreeNode> selectElements) {
List<IInterpreterInfo> changedInfos = new ArrayList<>();
HashSet<TreeNode> set = new HashSet<TreeNode>(selectElements.size());
set.addAll(selectElements);
for (Object n : root.getChildren()) {
DataAndImageTreeNode interpreterNode = (DataAndImageTreeNode) n;
if (set.contains(interpreterNode)) {
IInterpreterInfo info = (IInterpreterInfo) interpreterNode.getData();
List<String> pythonPath = info.getPythonPath();
boolean changed = false;
OrderedSet<String> newPythonPath = new OrderedSet<String>(pythonPath);
for (Object entryNode : interpreterNode.getChildren()) {
DataAndImageTreeNode pythonpathNode = (DataAndImageTreeNode) entryNode;
if (set.contains(pythonpathNode)) {
PythonpathChange change = (PythonpathChange) pythonpathNode.data;
change.apply(newPythonPath);
changed = true;
}
}
if (changed) {
InterpreterInfo copy = (InterpreterInfo) info.makeCopy();
copy.libs.clear();
copy.libs.addAll(newPythonPath);
changedInfos.add(copy);
}
}
}
return changedInfos;
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class SimpleJythonRunner method makeExecutableCommandStrWithVMArgs.
/**
* @param script
* @return
* @throws IOException
* @throws MisconfigurationException
*/
public static String[] makeExecutableCommandStrWithVMArgs(String jythonJar, String script, String basePythonPath, String vmArgs, String... args) throws IOException, JDTNotAvailableException, MisconfigurationException {
IInterpreterManager interpreterManager = InterpreterManagersAPI.getJythonInterpreterManager();
String javaLoc = FileUtils.getFileAbsolutePath(JavaVmLocationFinder.findDefaultJavaExecutable());
File file = new File(javaLoc);
if (file.exists() == false) {
throw new RuntimeException("The java location found does not exist. " + javaLoc);
}
if (file.isDirectory() == true) {
throw new RuntimeException("The java location found is a directory. " + javaLoc);
}
if (!new File(jythonJar).exists()) {
throw new RuntimeException(StringUtils.format("Error. The default configured interpreter: %s does not exist!", jythonJar));
}
InterpreterInfo info = (InterpreterInfo) interpreterManager.getInterpreterInfo(jythonJar, new NullProgressMonitor());
// pythonpath is: base path + libs path.
String libs = SimpleRunner.makePythonPathEnvFromPaths(info.libs);
FastStringBuffer jythonPath = new FastStringBuffer(basePythonPath, 128);
String pathSeparator = SimpleRunner.getPythonPathSeparator();
if (jythonPath.length() != 0) {
jythonPath.append(pathSeparator);
}
jythonPath.append(libs);
// may have the dir or be null
String cacheDir = null;
try {
AstPlugin plugin = AstPlugin.getDefault();
if (plugin != null) {
IPath stateLocation = plugin.getStateLocation();
File cacheDirFile = new File(stateLocation.toFile(), "jython_cache_dir");
cacheDirFile.mkdirs();
cacheDir = PydevPrefs.getEclipsePreferences().get(IInterpreterManager.JYTHON_CACHE_DIR, cacheDirFile.toString());
}
} catch (AssertionFailedException e) {
// this may happen while running the tests... it should be ok.
cacheDir = null;
}
if (cacheDir != null && cacheDir.trim().length() == 0) {
cacheDir = null;
}
if (cacheDir != null) {
cacheDir = "-Dpython.cachedir=" + cacheDir.trim();
}
String[] vmArgsList = ProcessUtils.parseArguments(vmArgs);
String[] s = new String[] { "-Dpython.path=" + jythonPath.toString(), "-classpath", jythonJar + pathSeparator + jythonPath, "org.python.util.jython", script };
List<String> asList = new ArrayList<String>();
asList.add(javaLoc);
if (cacheDir != null) {
asList.add(cacheDir);
}
asList.addAll(Arrays.asList(vmArgsList));
asList.addAll(Arrays.asList(s));
asList.addAll(Arrays.asList(args));
return asList.toArray(new String[0]);
}
Aggregations