Search in sources :

Example 96 with MisconfigurationException

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;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Tuple(org.python.pydev.shared_core.structure.Tuple) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Example 97 with MisconfigurationException

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();
}
Also used : SimpleRunner(org.python.pydev.ast.runners.SimpleRunner) PythonNature(org.python.pydev.plugin.nature.PythonNature) ArrayList(java.util.ArrayList) ExternalAnalizerProcessWatchDoc(com.python.pydev.analysis.external.ExternalAnalizerProcessWatchDoc) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) StringTokenizer(java.util.StringTokenizer) SimplePythonRunner(org.python.pydev.ast.runners.SimplePythonRunner) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 98 with MisconfigurationException

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;
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) RefactoringInfo(org.python.pydev.refactoring.core.base.RefactoringInfo)

Example 99 with MisconfigurationException

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));
}
Also used : IToken(org.python.pydev.core.IToken) BadLocationException(org.eclipse.jface.text.BadLocationException) CoreException(org.eclipse.core.runtime.CoreException) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) CompletionRecursionException(org.python.pydev.core.structure.CompletionRecursionException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) TokensList(org.python.pydev.core.TokensList) CompletionsShell(org.python.pydev.ast.codecompletion.shell.CompletionsShell)

Aggregations

MisconfigurationException (org.python.pydev.core.MisconfigurationException)99 IPythonNature (org.python.pydev.core.IPythonNature)28 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CoreException (org.eclipse.core.runtime.CoreException)18 IOException (java.io.IOException)14 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 IDocument (org.eclipse.jface.text.IDocument)13 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)13 IInterpreterManager (org.python.pydev.core.IInterpreterManager)12 PythonNatureWithoutProjectException (org.python.pydev.core.PythonNatureWithoutProjectException)12 HashSet (java.util.HashSet)11 IModule (org.python.pydev.core.IModule)11 BadLocationException (org.eclipse.jface.text.BadLocationException)10 SimpleNode (org.python.pydev.parser.jython.SimpleNode)10 AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)9 IFile (org.eclipse.core.resources.IFile)9 IGrammarVersionProvider (org.python.pydev.core.IGrammarVersionProvider)9 TokensList (org.python.pydev.core.TokensList)9