use of org.python.pydev.plugin.nature.SystemPythonNature in project Pydev by fabioz.
the class PipPackageManager method list.
/**
* To be called from any thread
*/
@Override
public List<String[]> list() {
List<String[]> listed = new ArrayList<String[]>();
File pipExecutable;
Tuple<String, String> output;
try {
pipExecutable = interpreterInfo.searchExecutableForInterpreter("pip", false);
// use system encoding
String encoding = null;
output = new SimpleRunner().runAndGetOutput(new String[] { pipExecutable.toString(), "list", "--format=columns" }, null, null, null, encoding);
} catch (UnableToFindExecutableException e) {
IPythonNature nature = new SystemPythonNature(interpreterInfo.getModulesManager().getInterpreterManager(), interpreterInfo);
String[] parameters = SimplePythonRunner.preparePythonCallParameters(interpreterInfo.getExecutableOrJar(), "-m", new String[] { getPipModuleName(interpreterInfo), "list", "--format=columns" });
output = new SimplePythonRunner().runAndGetOutput(parameters, null, nature, null, "utf-8");
}
List<String> splitInLines = StringUtils.splitInLines(output.o1, false);
for (String line : splitInLines) {
line = line.trim();
List<String> split = StringUtils.split(line, ' ');
if (split.size() == 2) {
String p0 = split.get(0).trim();
String p1 = split.get(1).trim();
if (p0.toLowerCase().equals("package") && p1.toLowerCase().equals("version")) {
continue;
}
if (p0.toLowerCase().startsWith("--") && p1.toLowerCase().startsWith("--")) {
continue;
}
listed.add(new String[] { p0.trim(), p1.trim(), "<pip>" });
}
}
if (output.o2.toLowerCase().contains("no module named pip")) {
listed.add(new String[] { "pip not installed (or not found) in interpreter", "", "" });
} else {
for (String s : StringUtils.iterLines(output.o2)) {
listed.add(new String[] { s, "", "" });
}
}
return listed;
}
use of org.python.pydev.plugin.nature.SystemPythonNature in project Pydev by fabioz.
the class RefactorerFindReferences method findPossibleReferences.
/**
* Find the references that may have the text we're looking for.
*
* @param request the request with the info for the find
* @return an array of IFile with the files that may have the references we're
* interested about (note that those may not actually contain the matches we're
* interested in -- it is just a helper to refine our search).
*/
public List<Tuple<List<ModulesKey>, IPythonNature>> findPossibleReferences(RefactoringRequest request) throws OperationCanceledException {
String initialName = request.qualifier;
List<Tuple<List<ModulesKey>, IPythonNature>> ret = request.getPossibleReferences(initialName);
if (ret != null) {
return ret;
}
if (FORCED_RETURN != null) {
ret = new ArrayList<Tuple<List<ModulesKey>, IPythonNature>>();
for (Tuple<List<ModulesKey>, IPythonNature> f : FORCED_RETURN) {
// only for testing purposes
for (ModulesKey k : f.o1) {
String object = FileUtils.getFileContents(k.file);
if (object.indexOf(request.qualifier) != -1) {
ret.add(new Tuple<List<ModulesKey>, IPythonNature>(Arrays.asList(k), f.o2));
}
}
}
return ret;
}
ret = new ArrayList<Tuple<List<ModulesKey>, IPythonNature>>();
try {
try {
IProject project = request.nature.getProject();
List<Tuple<AbstractAdditionalTokensInfo, IPythonNature>> infoAndNature = null;
if (project == null) {
if (request.nature instanceof SystemPythonNature) {
SystemPythonNature systemPythonNature = (SystemPythonNature) request.nature;
int interpreterType = systemPythonNature.getInterpreterType();
List<IPythonNature> naturesRelatedTo = PythonNature.getPythonNaturesRelatedTo(interpreterType);
infoAndNature = new ArrayList<Tuple<AbstractAdditionalTokensInfo, IPythonNature>>();
for (IPythonNature iPythonNature : naturesRelatedTo) {
if (iPythonNature.getProject() != null && iPythonNature.getProject().isAccessible()) {
AbstractAdditionalTokensInfo o1 = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(iPythonNature);
if (o1 != null) {
infoAndNature.add(new Tuple<AbstractAdditionalTokensInfo, IPythonNature>(o1, iPythonNature));
}
}
}
}
} else {
infoAndNature = AdditionalProjectInterpreterInfo.getAdditionalInfoAndNature(request.nature, false, true, true);
}
if (infoAndNature == null || infoAndNature.size() == 0) {
return ret;
}
// long initial = System.currentTimeMillis();
request.getMonitor().beginTask("Find possible references", infoAndNature.size());
request.getMonitor().setTaskName("Find possible references");
try {
for (Tuple<AbstractAdditionalTokensInfo, IPythonNature> tuple : infoAndNature) {
try {
SubProgressMonitor sub = new SubProgressMonitor(request.getMonitor(), 1);
request.pushMonitor(sub);
if (tuple.o1 instanceof AdditionalProjectInterpreterInfo && tuple.o2 != null) {
AdditionalProjectInterpreterInfo info = (AdditionalProjectInterpreterInfo) tuple.o1;
List<ModulesKey> modulesWithToken = info.getModulesWithToken(initialName, sub);
if (sub.isCanceled()) {
break;
}
ret.add(new Tuple<List<ModulesKey>, IPythonNature>(modulesWithToken, tuple.o2));
}
} finally {
request.popMonitor().done();
}
}
} finally {
request.getMonitor().done();
}
// System.out.println("Total: " + ((System.currentTimeMillis() - initial) / 1000.));
} catch (MisconfigurationException e) {
throw new RuntimeException(e);
}
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
request.setPossibleReferences(initialName, ret);
return ret;
}
use of org.python.pydev.plugin.nature.SystemPythonNature in project Pydev by fabioz.
the class CtxParticipant method computeConsoleCompletions.
// Console completions ---------------------------------------------------------------------------------------------
/**
* IPyDevCompletionParticipant2
*/
@Override
public Collection<ICompletionProposalHandle> computeConsoleCompletions(ActivationTokenAndQualifier tokenAndQual, Set<IPythonNature> naturesUsed, IScriptConsoleViewer viewer, int requestOffset) {
List<ICompletionProposalHandle> completions = new ArrayList<ICompletionProposalHandle>();
if (tokenAndQual.activationToken != null && tokenAndQual.activationToken.length() > 0) {
// we only want
return completions;
}
String qual = tokenAndQual.qualifier;
if (qual.length() >= PyCodeCompletionPreferences.getCharsForContextInsensitiveGlobalTokensCompletion() && naturesUsed != null && naturesUsed.size() > 0) {
// at least n characters required...
boolean addAutoImport = AnalysisPreferences.doAutoImport(null);
int qlen = qual.length();
boolean useSubstringMatchInCodeCompletion = PyCodeCompletionPreferences.getUseSubstringMatchInCodeCompletion();
IFilter nameFilter = PyCodeCompletionUtils.getNameFilter(useSubstringMatchInCodeCompletion, qual);
for (IPythonNature nature : naturesUsed) {
AbstractAdditionalTokensInfo additionalInfo;
try {
if (nature instanceof SystemPythonNature) {
SystemPythonNature systemPythonNature = (SystemPythonNature) nature;
additionalInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(systemPythonNature.getRelatedInterpreterManager(), systemPythonNature.getProjectInterpreter().getExecutableOrJar());
fillNatureCompletionsForConsole(viewer, requestOffset, completions, qual, addAutoImport, qlen, nameFilter, nature, additionalInfo, useSubstringMatchInCodeCompletion);
} else {
additionalInfo = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
fillNatureCompletionsForConsole(viewer, requestOffset, completions, qual, addAutoImport, qlen, nameFilter, nature, additionalInfo, useSubstringMatchInCodeCompletion);
}
} catch (MisconfigurationException e) {
Log.log(e);
}
}
}
return completions;
}
use of org.python.pydev.plugin.nature.SystemPythonNature 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.plugin.nature.SystemPythonNature in project Pydev by fabioz.
the class SystemModulesManager method getNature.
@Override
public IPythonNature getNature() {
if (nature == null) {
IInterpreterManager manager = getInterpreterManager();
nature = new SystemPythonNature(manager, this.info);
}
return nature;
}
Aggregations