Search in sources :

Example 1 with IExternalCodeAnalysisStream

use of com.python.pydev.analysis.external.IExternalCodeAnalysisStream in project Pydev by fabioz.

the class PyLintVisitor method startVisit.

/**
 * When we start visiting some resource, we create the process which will do the PyLint analysis.
 */
@Override
public void startVisit() {
    if (resource == null || PyLintPreferences.usePyLint(resource) == false || (document == null && !(resource instanceof IContainer))) {
        deleteMarkers();
        return;
    }
    IProject project = resource.getProject();
    PythonNature pythonNature = PythonNature.getPythonNature(project);
    if (pythonNature == null) {
        deleteMarkers();
        return;
    }
    File pyLintLocation = PyLintPreferences.getPyLintLocation(pythonNature, resource);
    if (pyLintLocation == null || !FileUtils.enhancedIsFile(pyLintLocation)) {
        deleteMarkers();
        return;
    }
    try {
        // PyLint can only be used for python projects
        if (pythonNature.getInterpreterType() != IInterpreterManager.INTERPRETER_TYPE_PYTHON) {
            deleteMarkers();
            return;
        }
    } catch (Exception e) {
        deleteMarkers();
        return;
    }
    synchronized (lock) {
        if (pyLintRunnable != null) {
            // (we should be analyzing multiple resources in a single call).
            return;
        }
        if (project != null) {
            if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                IPath location = file.getLocation();
                if (location != null) {
                    pyLintRunnable = new PyLintAnalysis(resource, document, location, new NullProgressMonitorWrapper(monitor), pyLintLocation);
                    try {
                        IExternalCodeAnalysisStream out = PyLintPreferences.getConsoleOutputStream(resource);
                        pyLintRunnable.createPyLintProcess(out);
                    } catch (final Exception e) {
                        Log.log(e);
                    }
                }
            } else if (resource instanceof IContainer) {
                IContainer dir = (IContainer) resource;
                IPath location = dir.getLocation();
                if (location != null) {
                    pyLintRunnable = new PyLintAnalysis(resource, null, location, new NullProgressMonitorWrapper(monitor), pyLintLocation);
                    try {
                        IExternalCodeAnalysisStream out = PyLintPreferences.getConsoleOutputStream(resource);
                        pyLintRunnable.createPyLintProcess(out);
                    } catch (final Exception e) {
                        Log.log(e);
                    }
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PythonNature(org.python.pydev.plugin.nature.PythonNature) IPath(org.eclipse.core.runtime.IPath) IExternalCodeAnalysisStream(com.python.pydev.analysis.external.IExternalCodeAnalysisStream) NullProgressMonitorWrapper(org.python.pydev.shared_core.progress.NullProgressMonitorWrapper) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject)

Example 2 with IExternalCodeAnalysisStream

use of com.python.pydev.analysis.external.IExternalCodeAnalysisStream in project Pydev by fabioz.

the class MypyVisitor method startVisit.

/**
 * When we start visiting some resource, we create the process which will do the Mypy analysis.
 */
@Override
public void startVisit() {
    if (resource == null || MypyPreferences.useMypy(resource) == false || (document == null && !(resource instanceof IContainer))) {
        deleteMarkers();
        return;
    }
    IProject project = resource.getProject();
    PythonNature pythonNature = PythonNature.getPythonNature(project);
    if (pythonNature == null) {
        deleteMarkers();
        return;
    }
    File mypyLocation = MypyPreferences.getMypyLocation(pythonNature);
    if (mypyLocation == null || !FileUtils.enhancedIsFile(mypyLocation)) {
        if (mypyLocation == null) {
            Log.log("Unable to find mypy. Project: " + project.getName());
        } else {
            Log.log("mypy location does not exist: " + mypyLocation);
        }
        deleteMarkers();
        return;
    }
    try {
        // Mypy can only be used for python projects
        if (pythonNature.getInterpreterType() != IInterpreterManager.INTERPRETER_TYPE_PYTHON) {
            deleteMarkers();
            return;
        }
    } catch (Exception e) {
        deleteMarkers();
        return;
    }
    synchronized (lock) {
        if (mypyRunnable != null) {
            // (we should be analyzing multiple resources in a single call).
            return;
        }
        if (project != null) {
            if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                IPath location = file.getLocation();
                if (location != null) {
                    mypyRunnable = new MypyAnalysis(resource, document, location, new NullProgressMonitorWrapper(monitor), mypyLocation);
                    try {
                        IExternalCodeAnalysisStream out = MypyPreferences.getConsoleOutputStream(project);
                        mypyRunnable.createMypyProcess(out);
                    } catch (final Exception e) {
                        Log.log(e);
                    }
                }
            } else if (resource instanceof IContainer) {
                IContainer dir = (IContainer) resource;
                IPath location = dir.getLocation();
                if (location != null) {
                    mypyRunnable = new MypyAnalysis(resource, null, location, new NullProgressMonitorWrapper(monitor), mypyLocation);
                    try {
                        IExternalCodeAnalysisStream out = MypyPreferences.getConsoleOutputStream(project);
                        mypyRunnable.createMypyProcess(out);
                    } catch (final Exception e) {
                        Log.log(e);
                    }
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PythonNature(org.python.pydev.plugin.nature.PythonNature) IPath(org.eclipse.core.runtime.IPath) IExternalCodeAnalysisStream(com.python.pydev.analysis.external.IExternalCodeAnalysisStream) NullProgressMonitorWrapper(org.python.pydev.shared_core.progress.NullProgressMonitorWrapper) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject)

Example 3 with IExternalCodeAnalysisStream

use of com.python.pydev.analysis.external.IExternalCodeAnalysisStream in project Pydev by fabioz.

the class Flake8Visitor method startVisit.

/**
 * When we start visiting some resource, we create the process which will do the Flake8 analysis.
 */
@Override
public void startVisit() {
    if (resource == null || Flake8Preferences.useFlake8(resource) == false || (document == null && !(resource instanceof IContainer))) {
        deleteMarkers();
        return;
    }
    IProject project = resource.getProject();
    PythonNature pythonNature = PythonNature.getPythonNature(project);
    if (pythonNature == null) {
        deleteMarkers();
        return;
    }
    File flake8Location = Flake8Preferences.getFlake8Location(pythonNature);
    if (flake8Location == null || !FileUtils.enhancedIsFile(flake8Location)) {
        if (flake8Location == null) {
            Log.log("Unable to find flake8. Project: " + project.getName());
        } else {
            Log.log("flake8 location does not exist: " + flake8Location);
        }
        deleteMarkers();
        return;
    }
    try {
        // Flake8 can only be used for python projects
        if (pythonNature.getInterpreterType() != IInterpreterManager.INTERPRETER_TYPE_PYTHON) {
            deleteMarkers();
            return;
        }
    } catch (Exception e) {
        deleteMarkers();
        return;
    }
    synchronized (lock) {
        if (flake8Runnable != null) {
            // (we should be analyzing multiple resources in a single call).
            return;
        }
        if (project != null) {
            if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                IPath location = file.getLocation();
                if (location != null) {
                    flake8Runnable = new Flake8Analysis(resource, document, location, new NullProgressMonitorWrapper(monitor), flake8Location);
                    try {
                        IExternalCodeAnalysisStream out = Flake8Preferences.getConsoleOutputStream(project);
                        flake8Runnable.createFlake8Process(out);
                    } catch (final Exception e) {
                        Log.log(e);
                    }
                }
            } else if (resource instanceof IContainer) {
                IContainer dir = (IContainer) resource;
                IPath location = dir.getLocation();
                if (location != null) {
                    flake8Runnable = new Flake8Analysis(resource, null, location, new NullProgressMonitorWrapper(monitor), flake8Location);
                    try {
                        IExternalCodeAnalysisStream out = Flake8Preferences.getConsoleOutputStream(project);
                        flake8Runnable.createFlake8Process(out);
                    } catch (final Exception e) {
                        Log.log(e);
                    }
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PythonNature(org.python.pydev.plugin.nature.PythonNature) IPath(org.eclipse.core.runtime.IPath) IExternalCodeAnalysisStream(com.python.pydev.analysis.external.IExternalCodeAnalysisStream) NullProgressMonitorWrapper(org.python.pydev.shared_core.progress.NullProgressMonitorWrapper) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject)

Aggregations

IExternalCodeAnalysisStream (com.python.pydev.analysis.external.IExternalCodeAnalysisStream)3 File (java.io.File)3 IContainer (org.eclipse.core.resources.IContainer)3 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 IPath (org.eclipse.core.runtime.IPath)3 PythonNature (org.python.pydev.plugin.nature.PythonNature)3 NullProgressMonitorWrapper (org.python.pydev.shared_core.progress.NullProgressMonitorWrapper)3