use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method testScheduleCheckForUpdates.
public void testScheduleCheckForUpdates() throws Exception {
setupEnv();
Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfo = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
SyncSystemModulesManagerScheduler scheduler = new SyncSystemModulesManagerScheduler();
final Set changes = Collections.synchronizedSet(new HashSet<>());
try {
Set<Entry<IInterpreterManager, Map<String, IInterpreterInfo>>> entrySet = managerToNameToInfo.entrySet();
SyncSystemModulesManagerScheduler.IInfoTrackerListener listener = new IInfoTrackerListener() {
@Override
public void onChangedIInterpreterInfo(InfoTracker infoTracker, File file) {
changes.add(file);
}
};
for (Entry<IInterpreterManager, Map<String, IInterpreterInfo>> entry : entrySet) {
Map<String, IInterpreterInfo> value = entry.getValue();
scheduler.afterSetInfos(entry.getKey(), value.values().toArray(new IInterpreterInfo[value.size()]), listener);
}
final File module4File = new File(libDir, "module4.py");
FileUtils.writeStrToFile("class Module3:pass", module4File);
TestUtils.waitUntilCondition(new ICallback<String, Object>() {
@Override
public String call(Object arg) {
if (changes.contains(module4File)) {
return null;
}
return "Changes not found.";
}
});
changes.clear();
final File myPthFile = new File(libDir, "my.pth");
FileUtils.writeStrToFile("./setuptools-1.1.6-py2.6.egg", myPthFile);
TestUtils.waitUntilCondition(new ICallback<String, Object>() {
@Override
public String call(Object arg) {
if (changes.contains(myPthFile)) {
return null;
}
return "Changes not found.";
}
});
synchronized (this) {
// Wait a bit as we may have 2 notifications (for creation and modification of the pth).
this.wait(250);
}
// Now, add an unrelated directory: no notifications are expected then.
changes.clear();
final File myUnrelatedDir = new File(libDir, "unrelatedDir");
myUnrelatedDir.mkdir();
synchronized (this) {
this.wait(250);
}
// no changes expected
assertEquals(new HashSet<>(), changes);
} finally {
scheduler.stop();
}
changes.clear();
final File myPthFile2 = new File(libDir, "my2.pth");
FileUtils.writeStrToFile("./setuptools-1.1.7-py2.6.egg", myPthFile2);
synchronized (this) {
this.wait(250);
}
assertEquals(new HashSet<>(), changes);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class CodeCompletionTestsBase method afterRestorSystemPythonPath.
/**
* @param info the information for the system manager that we just restored
*/
protected void afterRestorSystemPythonPath(InterpreterInfo info) {
// has to be restored for the project, as we just restored the system pythonpath
nature = null;
// ok, the system manager must be there
assertTrue(info.getModulesManager().getSize(true) > 0);
// and it must be registered as the pydev interpreter manager
IInterpreterManager iMan2 = getInterpreterManager();
InterpreterInfo info2;
try {
info2 = (InterpreterInfo) iMan2.getDefaultInterpreterInfo(false);
} catch (MisconfigurationException e) {
throw new RuntimeException(e);
}
assertTrue(info2 == info);
// does it have the loaded modules?
assertTrue(info2.getModulesManager().getSize(true) > 0);
assertTrue(info2.getModulesManager().getBuiltins().length > 0);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class InterpreterInfoBuilder method syncInfoToPythonPath.
@Override
public BuilderResult syncInfoToPythonPath(IProgressMonitor monitor, InterpreterInfo info) {
ISystemModulesManager modulesManager = info.getModulesManager();
IInterpreterManager manager = modulesManager.getInterpreterManager();
AbstractAdditionalDependencyInfo additionalInfo;
try {
additionalInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(manager, info.getExecutableOrJar());
} catch (MisconfigurationException e) {
Log.log(e);
return BuilderResult.OK;
}
return this.syncInfoToPythonPath(monitor, info, additionalInfo);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AttachToProcess method doIt.
protected void doIt() throws Exception {
IProcessList processList = PlatformUtils.getProcessList();
IProcessInfo[] processList2 = processList.getProcessList();
TreeNode<Object> root = new TreeNode<Object>(null, null);
for (IProcessInfo iProcessInfo : processList2) {
new TreeNode<>(root, iProcessInfo);
}
TreeNode<Object> element = new Select1Dialog() {
@Override
protected String getInitialFilter() {
return "*python*";
}
@Override
protected ILabelProvider getLabelProvider() {
return new TreeNodeLabelProvider() {
@Override
public Image getImage(Object element) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PUBLIC_ATTR_ICON));
}
@SuppressWarnings("unchecked")
@Override
public String getText(Object element) {
if (element == null) {
return "null";
}
TreeNode<Object> node = (TreeNode<Object>) element;
Object data = node.data;
if (data instanceof IProcessInfo) {
IProcessInfo iProcessInfo = (IProcessInfo) data;
return iProcessInfo.getPid() + " - " + iProcessInfo.getName();
}
return "Unexpected: " + data;
}
};
}
}.selectElement(root);
if (element != null) {
IProcessInfo p = (IProcessInfo) element.data;
int pid = p.getPid();
if (!PydevRemoteDebuggerServer.isRunning()) {
// I.e.: the remote debugger server must be on so that we can attach to it.
PydevRemoteDebuggerServer.startServer();
}
// Select interpreter
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IInterpreterManager interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
if (interpreterManager == null) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreter manager.", "No interpreter manager was available for attaching to a process.");
}
IInterpreterInfo[] interpreters = interpreterManager.getInterpreterInfos();
if (interpreters == null || interpreters.length == 0) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreters for creating console", "An interpreter that matches the architecture of the target process must be configured in the interpreter preferences.");
return;
}
SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(workbenchWindow, interpreters, "Select interpreter which matches the architecture of the target process (i.e.: 32/64 bits).", false);
int open = listDialog.open();
if (open != ListDialog.OK || listDialog.getResult().length != 1) {
return;
}
Object[] result = listDialog.getResult();
IInterpreterInfo interpreter;
if (result == null || result.length == 0) {
interpreter = interpreters[0];
} else {
interpreter = ((IInterpreterInfo) result[0]);
}
SimplePythonRunner runner = new SimplePythonRunner();
IPath relative = new Path("pysrc").append("pydevd_attach_to_process").append("attach_pydevd.py");
String script = CorePlugin.getBundleInfo().getRelativePath(relative).getAbsolutePath();
String[] args = new String[] { "--port", "" + DebugPluginPrefsInitializer.getRemoteDebuggerPort(), "--pid", "" + pid, "--protocol", "http" };
IPythonNature nature = new SystemPythonNature(interpreterManager, interpreter);
String[] s = SimplePythonRunner.preparePythonCallParameters(interpreter.getExecutableOrJar(), script, args);
Tuple<Process, String> run = runner.run(s, (File) null, nature, new NullProgressMonitor());
if (run.o1 != null) {
ShowProcessOutputDialog dialog = new ShowProcessOutputDialog(UIUtils.getActiveShell(), run.o1);
dialog.open();
}
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManager method updateStructures.
/**
* Here we'll update the tree structure to be shown to the user with the changes (root).
* The managerToNameToInfo structure has the information on the interpreter manager and related
* interpreter infos for which the changes should be checked.
*/
public void updateStructures(IProgressMonitor monitor, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo, CreateInterpreterInfoCallback callback) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
IImageCache imageCache = SharedCorePlugin.getImageCache();
if (imageCache == null) {
imageCache = new IImageCache() {
@Override
public IImageHandle getStringDecorated(String key, String stringToAddToDecoration) {
return null;
}
@Override
public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation, String secondDecoration, int secondDecorationLocation) {
return null;
}
@Override
public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation) {
return null;
}
@Override
public IImageHandle getImageDecorated(String key, String decoration) {
return null;
}
@Override
public IImageDescriptor getDescriptor(String projectIcon) {
return null;
}
@Override
public IImageHandle get(String key) {
return null;
}
};
}
for (Tuple<IInterpreterManager, IInterpreterInfo> infos : managerToNameToInfo.getManagerAndInfos()) {
IInterpreterManager manager = infos.o1;
IInterpreterInfo internalInfo = infos.o2;
String executable = internalInfo.getExecutableOrJar();
IInterpreterInfo newInterpreterInfo = callback.createInterpreterInfo(manager, executable, monitor);
if (newInterpreterInfo == null) {
continue;
}
DefaultPathsForInterpreterInfo defaultPaths = new DefaultPathsForInterpreterInfo();
OrderedSet<String> newEntries = new OrderedSet<String>(newInterpreterInfo.getPythonPath());
newEntries.removeAll(internalInfo.getPythonPath());
// Iterate over the new entries to suggest what should be added (we already have only what's not there).
for (Iterator<String> it = newEntries.iterator(); it.hasNext(); ) {
String entryInPythonpath = it.next();
if (!defaultPaths.selectByDefault(entryInPythonpath) || !defaultPaths.exists(entryInPythonpath)) {
// Don't suggest the addition of entries in the workspace or entries which do not exist.
it.remove();
}
}
// Iterate over existing entries to suggest what should be removed.
OrderedSet<String> removedEntries = new OrderedSet<String>();
List<String> pythonPath = internalInfo.getPythonPath();
for (String string : pythonPath) {
if (!new File(string).exists()) {
// Only suggest a removal if it was removed from the filesystem.
removedEntries.add(string);
}
}
if (newEntries.size() > 0 || removedEntries.size() > 0) {
DataAndImageTreeNode<IInterpreterInfo> interpreterNode = new DataAndImageTreeNode<IInterpreterInfo>(root, internalInfo, imageCache.get(UIConstants.PY_INTERPRETER_ICON));
for (String s : newEntries) {
new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, true), imageCache.get(UIConstants.LIB_SYSTEM));
}
for (String s : removedEntries) {
new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, false), imageCache.get(UIConstants.REMOVE_LIB_SYSTEM));
}
}
}
}
Aggregations