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);
}
}
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;
}
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();
}
Aggregations