use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class AdditionalSystemInterpreterInfo method getAdditionalSystemInfo.
/**
* @param m the module manager that we want to get info on (python, jython...)
* @return the additional info for the system
* @throws MisconfigurationException
*/
public static AbstractAdditionalDependencyInfo getAdditionalSystemInfo(IInterpreterManager manager, String interpreter, boolean errorIfNotAvailable) throws MisconfigurationException {
Tuple<String, String> key = new Tuple<String, String>(manager.getManagerRelatedName(), interpreter);
synchronized (additionalSystemInfoLock) {
AbstractAdditionalDependencyInfo info = (AbstractAdditionalDependencyInfo) additionalSystemInfo.get(key);
if (info == null) {
// lazy-load.
info = new AdditionalSystemInterpreterInfo(manager, interpreter);
additionalSystemInfo.put(key, info);
if (!info.load()) {
try {
recreateAllInfo(manager, interpreter, new NullProgressMonitor());
info = (AbstractAdditionalDependencyInfo) additionalSystemInfo.get(key);
} catch (Exception e) {
Log.log(e);
}
}
}
return info;
}
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PyLintAnalysis method createPyLintProcess.
/**
* Creates the pylint process and starts getting its output.
*/
void createPyLintProcess(IExternalCodeAnalysisStream out) throws CoreException, MisconfigurationException, PythonNatureWithoutProjectException {
String script = FileUtils.getFileAbsolutePath(pyLintLocation);
String target = FileUtils.getFileAbsolutePath(new File(location.toOSString()));
// check whether lint.py module or pylint executable has been specified
boolean isPyScript = script.endsWith(".py") || script.endsWith(".pyw");
ArrayList<String> cmdList = new ArrayList<String>();
// pylint executable
if (!isPyScript) {
cmdList.add(script);
}
// user args
String userArgs = StringUtils.replaceNewLines(PyLintPreferences.getPyLintArgs(resource), " ");
StringTokenizer tokenizer2 = new StringTokenizer(userArgs);
while (tokenizer2.hasMoreTokens()) {
String token = tokenizer2.nextToken();
if (token.equals("--output-format=parseable")) {
continue;
}
if (token.startsWith("--msg-template=")) {
continue;
}
if (token.startsWith("--output-format=")) {
continue;
}
cmdList.add(token);
}
cmdList.add("--output-format=text");
cmdList.add("--msg-template='{C}:{line:3d},{column:2d}: ({symbol}) {msg}'");
// target file to be linted
cmdList.add(target);
String[] args = cmdList.toArray(new String[0]);
// run pylint in project location
IProject project = resource.getProject();
File workingDir = project.getLocation().toFile();
ICallback0<Process> launchProcessCallback;
if (isPyScript) {
// run Python script (lint.py) with the interpreter of current project
PythonNature nature = PythonNature.getPythonNature(project);
if (nature == null) {
Throwable e = new RuntimeException("PyLint ERROR: Nature not configured for: " + project);
Log.log(e);
return;
}
launchProcessCallback = () -> {
String interpreter;
try {
interpreter = nature.getProjectInterpreter().getExecutableOrJar();
} catch (Exception e) {
throw new RuntimeException(e);
}
WriteToStreamHelper.write("PyLint: Executing command line:", out, script, args);
SimplePythonRunner runner = new SimplePythonRunner();
String[] parameters = SimplePythonRunner.preparePythonCallParameters(interpreter, script, args);
Tuple<Process, String> r = runner.run(parameters, workingDir, nature, monitor);
return r.o1;
};
} else {
// run executable command (pylint or pylint.bat or pylint.exe)
launchProcessCallback = () -> {
WriteToStreamHelper.write("PyLint: Executing command line:", out, (Object) args);
SimpleRunner simpleRunner = new SimpleRunner();
Tuple<Process, String> r = simpleRunner.run(args, workingDir, PythonNature.getPythonNature(project), null);
return r.o1;
};
}
this.processWatchDoc = new ExternalAnalizerProcessWatchDoc(out, monitor, this, launchProcessCallback, null, false);
this.processWatchDoc.start();
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class TddRefactorCompletion method getExecuted.
private TemplateProposal getExecuted() {
if (executed == null) {
pyCreateAction.setActiveEditor(null, edit);
try {
RefactoringInfo refactoringInfo = new RefactoringInfo(edit, ps.getTextSelection());
executed = (TemplateProposal) pyCreateAction.createProposal(refactoringInfo, this.fReplacementString, this.locationStrategy, parametersAfterCall);
} catch (MisconfigurationException e) {
Log.log(e);
}
}
return executed;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PyCodeCompletion method fillTokensWithJediCompletions.
private static void fillTokensWithJediCompletions(CompletionRequest request, PySelection ps, IPythonNature nature, ICodeCompletionASTManager astManager, TokensOrProposalsList tokensList) throws IOException, CoreException, MisconfigurationException, PythonNatureWithoutProjectException {
try {
char c = ps.getCharBeforeCurrentOffset();
if (c == '(') {
System.out.println("Get call def.");
}
} catch (BadLocationException e) {
Log.log(e);
}
CompletionsShell shell = (CompletionsShell) AbstractShell.getServerShell(nature, AbstractShell.getShellId());
String charset = "utf-8";
// if (viewer instanceof PySourceViewer) {
// PySourceViewer pySourceViewer = (PySourceViewer) viewer;
// IEditorInput input = (IEditorInput) pySourceViewer.getAdapter(IEditorInput.class);
// final IFile file = (IFile) ((FileEditorInput) input).getAdapter(IFile.class);
// charset = file.getCharset();
// }
List<String> completePythonPath = astManager.getModulesManager().getCompletePythonPath(nature.getProjectInterpreter(), nature.getRelatedInterpreterManager());
List<IToken> completions;
try {
completions = shell.getJediCompletions(request.editorFile, ps, charset, completePythonPath);
} catch (Exception e) {
throw new RuntimeException(e);
}
tokensList.addAll(new TokensList(completions));
}
Aggregations