use of org.python.pydev.plugin.nature.SystemPythonNature in project Pydev by fabioz.
the class PyCodeCompletion2Test method testSelfOrClsCompletion.
public void testSelfOrClsCompletion() throws Exception {
String s = "" + "class B:\n" + " def m2(self):\n" + " pass\n" + "\n" + "class A:\n" + " m1 = B()\n" + " def foo(self):\n" + " self.m1." + "";
SystemPythonNature nature = new SystemPythonNature(PyCodeCompletion2Test.nature.getRelatedInterpreterManager());
PySelection ps = new PySelection(new Document(s), s.length() - 1);
ICompletionState state = new CompletionState(ps.getStartLineIndex(), ps.getAbsoluteCursorOffset() - ps.getStartLine().getOffset(), null, nature, "");
CompletionRequest request = new CompletionRequest(null, nature, ps.getDoc(), "self.m1", ps.getAbsoluteCursorOffset(), 0, new PyCodeCompletion(), "", false);
TokensList selfCompletions = new TokensList();
PyCodeCompletion.getSelfOrClsCompletions(request, selfCompletions, state, false, false, "self.m1");
assertEquals(1, selfCompletions.size());
assertEquals("m2", selfCompletions.getFirst().getRepresentation());
}
use of org.python.pydev.plugin.nature.SystemPythonNature in project Pydev by fabioz.
the class InterpreterConfigHelpers method createPipenvInterpreter.
public static ObtainInterpreterInfoOperation createPipenvInterpreter(IInterpreterInfo[] interpreterInfos, Shell shell, PrintWriter logger, Map<String, IInterpreterInfo> nameToInfo, String defaultProjectLocation, IInterpreterManager interpreterManager) throws Exception {
if (logger == null) {
logger = new PrintWriter(new ByteArrayOutputStream());
}
if (interpreterInfos == null || interpreterInfos.length == 0) {
PyDialogHelpers.openCritical("Unable to configure with pipenv", "Cannot configure with pipenv without a base interpreter configured. Please configure the base interpreter first.");
return null;
}
PipenvDialog pipenvDialog = new PipenvDialog(shell, interpreterInfos, null, defaultProjectLocation, interpreterManager, "New Pipenv interpreter", true);
if (pipenvDialog.open() == Dialog.OK) {
final IInterpreterInfo baseInterpreter = pipenvDialog.getBaseInterpreter();
final String executableOrJar = baseInterpreter.getExecutableOrJar();
final String pipenvLocation = pipenvDialog.getPipenvLocation();
final String projectLocation = pipenvDialog.getProjectLocation();
final SystemPythonNature nature = new SystemPythonNature(interpreterManager, baseInterpreter);
File pythonVenvFromLocation = PipenvHelper.getPythonExecutableFromProjectLocationWithPipenv(pipenvLocation, new File(projectLocation));
if (pythonVenvFromLocation == null) {
PipenvPackageManager.create(executableOrJar, pipenvLocation, projectLocation, nature);
// Get the one just created.
pythonVenvFromLocation = PipenvHelper.getPythonExecutableFromProjectLocationWithPipenv(pipenvLocation, new File(projectLocation));
}
if (pythonVenvFromLocation != null) {
NameAndExecutable interpreterNameAndExecutable = new NameAndExecutable(new File(projectLocation).getName() + " (pipenv)", pythonVenvFromLocation.getAbsolutePath());
boolean foundError = canAddNameAndExecutable(logger, interpreterNameAndExecutable, nameToInfo, shell);
if (foundError) {
return null;
}
logger.println("- Chosen interpreter (name and file):'" + interpreterNameAndExecutable);
if (interpreterNameAndExecutable != null && interpreterNameAndExecutable.o2 != null) {
// ok, now that we got the file, let's see if it is valid and get the library info.
ObtainInterpreterInfoOperation ret = tryInterpreter(interpreterNameAndExecutable, interpreterManager, false, true, logger, shell);
if (ret != null && ret.result != null) {
ret.result.setPipenvTargetDir(projectLocation);
}
return ret;
}
}
}
return null;
}
Aggregations