Search in sources :

Example 86 with PythonNature

use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.

the class AnalysisBuilderVisitor method visitRemovedResource.

@Override
public void visitRemovedResource(IResource resource, ICallback0<IDocument> document, IProgressMonitor monitor) {
    PythonNature nature = getPythonNature(resource);
    if (nature == null) {
        return;
    }
    if (resource.getType() == IResource.FOLDER) {
        // We don't need to explicitly treat any folder (just its children -- such as __init__ and submodules)
        return;
    }
    if (!isFullBuild()) {
        // on a full build, it'll already remove all the info
        String moduleName;
        try {
            moduleName = getModuleName(resource, nature);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }
        long documentTime = this.getDocumentTime();
        if (documentTime == -1) {
            Log.log("Warning: The document time in the visitor for remove is -1. Changing for current time. " + "Resource: " + resource + ". Module name: " + moduleName);
            documentTime = System.currentTimeMillis();
        }
        long resourceModificationStamp = resource.getModificationStamp();
        final IAnalysisBuilderRunnable runnable = AnalysisBuilderRunnableFactory.createRunnable(moduleName, nature, isFullBuild(), false, AnalysisBuilderRunnable.ANALYSIS_CAUSE_BUILDER, documentTime, resourceModificationStamp);
        if (runnable == null) {
            // It may be null if the document version of the new one is lower than one already active.
            return;
        }
        execRunnable(moduleName, runnable, false);
    }
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Example 87 with PythonNature

use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.

the class AdditionalProjectInterpreterInfo method getPythonPathFolders.

@Override
protected Set<String> getPythonPathFolders() {
    PythonNature pythonNature = PythonNature.getPythonNature(project);
    IPythonPathNature pythonPathNature = pythonNature.getPythonPathNature();
    Set<String> ret = new HashSet<>();
    try {
        ret.addAll(StringUtils.split(pythonPathNature.getOnlyProjectPythonPathStr(true), "|"));
    } catch (CoreException e) {
        Log.log(e);
    }
    return ret;
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) CoreException(org.eclipse.core.runtime.CoreException) IPythonPathNature(org.python.pydev.core.IPythonPathNature) HashSet(java.util.HashSet)

Example 88 with PythonNature

use of org.python.pydev.plugin.nature.PythonNature 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)

Aggregations

PythonNature (org.python.pydev.plugin.nature.PythonNature)88 IProject (org.eclipse.core.resources.IProject)41 IPythonNature (org.python.pydev.core.IPythonNature)32 File (java.io.File)31 HashSet (java.util.HashSet)20 IFile (org.eclipse.core.resources.IFile)20 ArrayList (java.util.ArrayList)19 CoreException (org.eclipse.core.runtime.CoreException)18 IResource (org.eclipse.core.resources.IResource)17 IPath (org.eclipse.core.runtime.IPath)14 IContainer (org.eclipse.core.resources.IContainer)12 MisconfigurationException (org.python.pydev.core.MisconfigurationException)11 PythonSourceFolder (org.python.pydev.navigator.elements.PythonSourceFolder)10 HashMap (java.util.HashMap)9 IPythonPathNature (org.python.pydev.core.IPythonPathNature)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 ICodeCompletionASTManager (org.python.pydev.core.ICodeCompletionASTManager)8 IFolder (org.eclipse.core.resources.IFolder)7 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)7 Set (java.util.Set)6