use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManagerScheduler method start.
/**
* To be called when we start the plugin.
*
* Should be called only once (when we'll make a full check for the current integrity of the information)
* Later on, we'll start to check if things change in the PYTHONPATH based on changes in the filesystem.
*/
public void start() {
boolean scheduleInitially = false;
boolean reCheckOnFilesystemChanges = InterpreterGeneralPreferences.getReCheckOnFilesystemChanges();
IInterpreterManager[] managers = InterpreterManagersAPI.getAllInterpreterManagers();
for (IInterpreterManager iInterpreterManager : managers) {
if (iInterpreterManager != null) {
IInterpreterInfo[] interpreterInfos = iInterpreterManager.getInterpreterInfos();
if (reCheckOnFilesystemChanges) {
this.registerInterpreterManager(iInterpreterManager, interpreterInfos);
}
scheduleInitially = scheduleInitially || (interpreterInfos != null && interpreterInfos.length > 0);
}
}
// Default is waiting 30 seconds after startup
int timeout = 1000 * 30;
IEclipsePreferences preferences = PydevPrefs.getEclipsePreferences();
// Now we add builtin indexing on our checks (so, force it at least once).
boolean alreadyChecked = preferences.getBoolean("INTERPRETERS_CHECKED_ONCE", false);
boolean force = false;
if (!alreadyChecked) {
// Now we add builtin indexing on our checks (so, force it at least once).
preferences.putBoolean("INTERPRETERS_CHECKED_ONCE", true);
force = true;
// In this case, wait only 7 seconds after startup
timeout = 1000 * 7;
}
if (force || InterpreterGeneralPreferences.getCheckConsistentOnStartup()) {
if (scheduleInitially) {
// Only do the initial schedule if there's something to be tracked (otherwise, wait for some interpreter
// to be configured and work only on deltas already).
// The initial job will do a full check on what's available and if it's synched with the filesystem.
job.addAllToTrack();
// Wait a minute before starting our sync process.
job.scheduleLater(timeout);
}
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManagerScheduler method checkAllNow.
public void checkAllNow() {
// Add all to be tracked
Map<IInterpreterManager, Map<String, IInterpreterInfo>> addedToTrack = job.addAllToTrack();
// remove from the preferences any ignore the user had set previously
Set<Entry<IInterpreterManager, Map<String, IInterpreterInfo>>> entrySet = addedToTrack.entrySet();
IEclipsePreferences preferences = PydevPrefs.getEclipsePreferences();
for (Entry<IInterpreterManager, Map<String, IInterpreterInfo>> entry : entrySet) {
Set<Entry<String, IInterpreterInfo>> entrySet2 = entry.getValue().entrySet();
for (Entry<String, IInterpreterInfo> entry2 : entrySet2) {
String key = SyncSystemModulesManager.createKeyForInfo(entry2.getValue());
preferences.put(key, "");
}
}
try {
preferences.flush();
} catch (BackingStoreException e) {
Log.log(e);
}
// schedule changes to be executed.
job.scheduleLater(0);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SystemModulesManager method getNature.
@Override
public IPythonNature getNature() {
if (nature == null) {
IInterpreterManager manager = getInterpreterManager();
nature = new SystemPythonNature(manager, this.info);
}
return nature;
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class PythonNature method getProjectInterpreter.
/**
* @return info on the interpreter configured for this nature.
* @throws MisconfigurationException
*
* @note that an exception will be raised if the
*/
@Override
public IInterpreterInfo getProjectInterpreter() throws MisconfigurationException, PythonNatureWithoutProjectException {
if (this.project == null) {
throw new PythonNatureWithoutProjectException("Project is not set.");
}
try {
String projectInterpreterName = getProjectInterpreterName();
IInterpreterInfo ret = null;
IInterpreterManager relatedInterpreterManager = getRelatedInterpreterManager();
if (relatedInterpreterManager == null) {
if (IN_TESTS) {
return null;
}
throw new ProjectMisconfiguredException("Did not expect the interpreter manager to be null.");
}
if (IPythonNature.DEFAULT_INTERPRETER.equals(projectInterpreterName)) {
if (relatedInterpreterManager.getInterpreterType() == IPythonNature.INTERPRETER_TYPE_PYTHON) {
IPath location = this.project.getLocation();
if (location != null) {
File projectLocation = location.toFile();
ret = PipenvHelper.getPipenvInterpreterInfoForProjectLocation(relatedInterpreterManager.getInterpreterInfos(), projectLocation, relatedInterpreterManager);
}
}
if (ret == null) {
// if it's the default, let's translate it to the outside world
ret = relatedInterpreterManager.getDefaultInterpreterInfo(true);
}
} else {
ret = relatedInterpreterManager.getInterpreterInfo(projectInterpreterName, null);
}
if (ret == null) {
final IProject p = this.getProject();
final String projectName;
if (p != null) {
projectName = p.getName();
} else {
projectName = "null";
}
String msg = "Invalid interpreter: " + projectInterpreterName + " configured for project: " + projectName + ".";
ProjectMisconfiguredException e = new ProjectMisconfiguredException(msg);
Log.log(e);
throw e;
} else {
return ret;
}
} catch (CoreException e) {
throw new ProjectMisconfiguredException(e);
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class BlackRunner method formatWithBlack.
public static String formatWithBlack(IPythonNature nature, IDocument doc, FormatStd std, File workingDir) {
try {
Process process;
String[] parseArguments = ProcessUtils.parseArguments(std.blackParameters);
String cmdarrayAsStr;
String executableLocation = std.blackExecutableLocation;
if (!std.searchBlackInInterpreter && executableLocation != null && !executableLocation.isEmpty() && FileUtils.enhancedIsFile(new File(executableLocation))) {
SimpleRunner simpleRunner = new SimpleRunner();
String[] args = ArrayUtils.concatArrays(new String[] { executableLocation, "-" }, parseArguments);
Tuple<Process, String> r = simpleRunner.run(args, workingDir, null, null);
process = r.o1;
cmdarrayAsStr = r.o2;
} else {
if (nature == null) {
IInterpreterManager manager = InterpreterManagersAPI.getPythonInterpreterManager();
try {
nature = new SystemPythonNature(manager);
} catch (MisconfigurationException e) {
Log.log(e);
}
}
PythonRunner pythonRunner = new PythonRunner(nature);
Tuple<Process, String> processInfo = pythonRunner.createProcessFromModuleName("black", ArrayUtils.concatArrays(new String[] { "-" }, parseArguments), workingDir, new NullProgressMonitor());
process = processInfo.o1;
cmdarrayAsStr = processInfo.o2;
}
String pythonFileEncoding = FileUtils.getPythonFileEncoding(doc, null);
if (pythonFileEncoding == null) {
pythonFileEncoding = "utf-8";
}
process.getOutputStream().write(doc.get().getBytes(pythonFileEncoding));
Tuple<String, String> processOutput = ProcessUtils.getProcessOutput(process, cmdarrayAsStr, new NullProgressMonitor(), pythonFileEncoding);
if (process.exitValue() != 0) {
Log.log("Black formatter exited with: " + process.exitValue() + "\nStdout:\n" + processOutput.o1 + "\nStderr:\n" + processOutput.o2);
return null;
}
return processOutput.o1;
} catch (Exception e) {
Log.log(e);
}
return null;
}
Aggregations