use of org.python.pydev.core.IModulesManager in project Pydev by fabioz.
the class AdditionalProjectInterpreterInfo method recreateAllInfo.
public static void recreateAllInfo(IPythonNature nature, IProgressMonitor monitor) {
try (GlobalFeedbackReporter r = GlobalFeedback.start("Full projects reindex...")) {
synchronized (additionalNatureInfoLock) {
// Note: at this point we're 100% certain that the ast manager is there.
ICodeCompletionASTManager astManager = nature.getAstManager();
if (astManager == null) {
return;
}
IModulesManager m = astManager.getModulesManager();
if (m == null) {
return;
}
IProject project = nature.getProject();
AbstractAdditionalDependencyInfo currInfo = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
if (currInfo != null) {
currInfo.clearAllInfo();
currInfo.dispose();
}
String feedback = "(project:" + project.getName() + ")";
synchronized (m) {
AbstractAdditionalDependencyInfo info = (AbstractAdditionalDependencyInfo) restoreInfoForModuleManager(monitor, m, feedback, new AdditionalProjectInterpreterInfo(project), nature, nature.getGrammarVersion());
if (info != null) {
// ok, set it and save it
additionalNatureInfo.put(FileUtilsFileBuffer.getValidProjectName(project), info);
info.save();
}
}
}
} catch (Exception e) {
Log.log(e);
throw new RuntimeException(e);
}
}
use of org.python.pydev.core.IModulesManager in project Pydev by fabioz.
the class MypyAnalysis method createMypyProcess.
/**
* Creates the mypy process and starts getting its output.
*/
void createMypyProcess(IExternalCodeAnalysisStream out) throws CoreException, MisconfigurationException, PythonNatureWithoutProjectException {
String mypyExecutable = FileUtils.getFileAbsolutePath(mypyLocation);
String target = location.toOSString();
ArrayList<String> cmdList = new ArrayList<String>();
cmdList.add(mypyExecutable);
String userArgs = StringUtils.replaceNewLines(MypyPreferences.getMypyArgs(resource), " ");
List<String> userArgsAsList = new ArrayList<>(Arrays.asList(ProcessUtils.parseArguments(userArgs)));
if (!userArgsAsList.contains("--show-column-numbers")) {
userArgsAsList.add("--show-column-numbers");
}
boolean foundFollowImports = false;
boolean foundCacheDir = false;
for (String arg : userArgsAsList) {
if (arg.startsWith("--follow-imports=silent")) {
foundFollowImports = true;
}
if (arg.startsWith("--cache-dir")) {
foundCacheDir = true;
}
}
if (!foundFollowImports) {
// We just want warnings for the current file.
userArgsAsList.add("--follow-imports=silent");
}
// run mypy in project location
IProject project = resource.getProject();
if (project == null || !project.isAccessible()) {
// If the project is no longer valid, we can't do much.
Log.log("Unable to run mypy in: " + target + ". Project not available (" + project + ").");
return;
}
File workingDir = project.getLocation().toFile();
if (!foundCacheDir) {
// Set a cache dir if one is not given.
userArgsAsList.add("--cache-dir=" + new File(workingDir, ".mypy_cache").toString());
}
cmdList.addAll(userArgsAsList);
cmdList.add(target);
String[] args = cmdList.toArray(new String[0]);
// run executable command (mypy or mypy.bat or mypy.exe)
WriteToStreamHelper.write("Mypy: Executing command line:", out, (Object) args);
IPythonNature nature = PythonNature.getPythonNature(project);
ICallback<String[], String[]> updateEnv = null;
if (MypyPreferences.getAddProjectFoldersToMyPyPath(resource)) {
Collection<String> addToMypyPath = new HashSet<String>();
IModulesManager[] managersInvolved = nature.getAstManager().getModulesManager().getManagersInvolved(false);
for (IModulesManager iModulesManager : managersInvolved) {
for (String s : StringUtils.split(iModulesManager.getNature().getPythonPathNature().getOnlyProjectPythonPathStr(true), "|")) {
if (!s.isEmpty()) {
addToMypyPath.add(s);
}
}
}
if (addToMypyPath.size() > 0) {
updateEnv = new ICallback<String[], String[]>() {
@Override
public String[] call(String[] arg) {
for (int i = 0; i < arg.length; i++) {
// Update var
if (arg[i].startsWith("MYPYPATH=")) {
arg[i] = arg[i] + SimpleRunner.getPythonPathSeparator() + StringUtils.join(SimpleRunner.getPythonPathSeparator(), addToMypyPath);
return arg;
}
}
// Create new var.
return ArrayUtils.concatArrays(arg, new String[] { "MYPYPATH=" + StringUtils.join(SimpleRunner.getPythonPathSeparator(), addToMypyPath) });
}
};
}
}
final ICallback<String[], String[]> finalUpdateEnv = updateEnv;
ICallback0<Process> launchProcessCallback = () -> {
SimpleRunner simpleRunner = new SimpleRunner();
final Tuple<Process, String> r = simpleRunner.run(args, workingDir, nature, null, finalUpdateEnv);
Process process = r.o1;
return process;
};
this.processWatchDoc = new ExternalAnalizerProcessWatchDoc(out, monitor, this, launchProcessCallback, project, true);
this.processWatchDoc.start();
}
use of org.python.pydev.core.IModulesManager in project Pydev by fabioz.
the class AbstractPythonNature method endRequests.
/**
* End a request for an ast manager (end caching things)
*/
@Override
public void endRequests() {
synchronized (modulesManagerStackLock) {
try {
IModulesManager modulesManager = modulesManagerStack.pop();
modulesManager.endCompletionCache();
} catch (EmptyStackException e) {
Log.log(e);
}
}
}
use of org.python.pydev.core.IModulesManager in project Pydev by fabioz.
the class AbstractPythonNature method startRequests.
/**
* Start a request for an ast manager (start caching things)
*/
@Override
public boolean startRequests() {
ICodeCompletionASTManager astManager = this.getAstManager();
if (astManager == null) {
return false;
}
IModulesManager modulesManager = astManager.getModulesManager();
if (modulesManager == null) {
return false;
}
synchronized (modulesManagerStackLock) {
modulesManagerStack.push(modulesManager);
return modulesManager.startCompletionCache();
}
}
use of org.python.pydev.core.IModulesManager in project Pydev by fabioz.
the class GlobalsTwoPanelElementSelector2 method fillContentProvider.
/**
* This is the place where we put all the info in the content provider. Note that here we must add
* ALL the info -- later, we'll filter it based on the active working set.
*/
@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
if (itemsFilter instanceof InfoFilter) {
if (progressMonitor != null) {
progressMonitor.beginTask("Searching...", this.additionalInfo.size());
}
for (AbstractAdditionalTokensInfo additionalInfo : this.additionalInfo) {
if (progressMonitor != null) {
if (progressMonitor.isCanceled()) {
return;
} else {
progressMonitor.worked(1);
}
}
// no duplicates
Collection<IInfo> allTokens = new HashSet<IInfo>(additionalInfo.getAllTokens());
for (IInfo iInfo : allTokens) {
contentProvider.add(new AdditionalInfoAndIInfo(additionalInfo, iInfo), itemsFilter);
}
// Also show to the user the modules available as globals (2.2.3)
IModulesManager modulesManager = null;
try {
if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
IProject project = projectInterpreterInfo.getProject();
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
ICodeCompletionASTManager astManager = nature.getAstManager();
if (astManager != null) {
modulesManager = astManager.getModulesManager();
}
}
} else if (additionalInfo instanceof AdditionalSystemInterpreterInfo) {
AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additionalInfo;
IInterpreterInfo defaultInterpreterInfo = systemInterpreterInfo.getManager().getDefaultInterpreterInfo(false);
modulesManager = defaultInterpreterInfo.getModulesManager();
}
} catch (Throwable e) {
Log.log(e);
}
if (modulesManager != null) {
SortedMap<ModulesKey, ModulesKey> allDirectModulesStartingWith = modulesManager.getAllDirectModulesStartingWith("");
Collection<ModulesKey> values = allDirectModulesStartingWith.values();
for (ModulesKey modulesKey : values) {
contentProvider.add(new AdditionalInfoAndIInfo(additionalInfo, new ModInfo(modulesKey.name, modulesManager.getNature(), modulesKey.file != null ? modulesKey.file.toString() : null, 1, 1)), itemsFilter);
}
}
}
}
if (progressMonitor != null) {
progressMonitor.done();
}
}
Aggregations