Search in sources :

Example 16 with InterpreterInfo

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);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PythonInterpreterManager(org.python.pydev.ast.interpreter_managers.PythonInterpreterManager) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo)

Example 17 with InterpreterInfo

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 };
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo)

Example 18 with InterpreterInfo

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 };
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo)

Example 19 with InterpreterInfo

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;
}
Also used : OrderedSet(org.python.pydev.shared_core.structure.OrderedSet) ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) DefaultPathsForInterpreterInfo(org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashSet(java.util.HashSet)

Example 20 with InterpreterInfo

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]);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IInterpreterManager(org.python.pydev.core.IInterpreterManager) AstPlugin(org.python.pydev.ast.AstPlugin) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) File(java.io.File) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException)

Aggregations

InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)34 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)27 IInterpreterManager (org.python.pydev.core.IInterpreterManager)13 ArrayList (java.util.ArrayList)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)7 HashMap (java.util.HashMap)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 File (java.io.File)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)4 PythonInterpreterManager (org.python.pydev.ast.interpreter_managers.PythonInterpreterManager)4 MisconfigurationException (org.python.pydev.core.MisconfigurationException)4 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)4 TreeNode (org.python.pydev.shared_core.structure.TreeNode)4 Tuple (org.python.pydev.shared_core.structure.Tuple)4 Map (java.util.Map)3 SyncSystemModulesManager (org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager)3 IInfo (org.python.pydev.core.IInfo)3