当前位置: 首页>>代码示例>>Java>>正文


Java PythonSdkType.findPythonSdk方法代码示例

本文整理汇总了Java中com.jetbrains.python.sdk.PythonSdkType.findPythonSdk方法的典型用法代码示例。如果您正苦于以下问题:Java PythonSdkType.findPythonSdk方法的具体用法?Java PythonSdkType.findPythonSdk怎么用?Java PythonSdkType.findPythonSdk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jetbrains.python.sdk.PythonSdkType的用法示例。


在下文中一共展示了PythonSdkType.findPythonSdk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateSphinxQuickStartRequiredAction

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public static Presentation updateSphinxQuickStartRequiredAction(final AnActionEvent e) {
  final Presentation presentation = e.getPresentation();

  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (project != null) {
    Module module = e.getData(LangDataKeys.MODULE);
    if (module == null) {
      Module[] modules = ModuleManager.getInstance(project).getModules();
      module = modules.length == 0 ? null : modules [0];
    }
    if (module != null) {
      Sdk sdk = PythonSdkType.findPythonSdk(module);
      if (sdk != null) {
        PyPackageManager manager = PyPackageManager.getInstance(sdk);
        try {
          final PyPackage sphinx = manager.findPackage("Sphinx", false);
          presentation.setEnabled(sphinx != null);
        }
        catch (ExecutionException ignored) {
        }
      }
    }
  }
  return presentation;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:RestPythonUtil.java

示例2: getProjectUsages

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) throws CollectUsagesException {
  final Set<UsageDescriptor> result = new HashSet<UsageDescriptor>();
  for(final Module m: ModuleManager.getInstance(project).getModules()) {
    final Sdk pythonSdk = PythonSdkType.findPythonSdk(m);
    if (pythonSdk != null) {
      ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override
        public void run() {
          List<PyRequirement> requirements = PyPackageManager.getInstance(pythonSdk).getRequirements(m);
          if (requirements != null) {
            Collection<String> packages = new HashSet<String>(PyPIPackageUtil.INSTANCE.getPackageNames());
            for (PyRequirement requirement : requirements) {
              String name = requirement.getName();
              if (packages.contains(name)) {
                result.add(new UsageDescriptor(name, 1));
              }
            }
          }
        }
      });
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:PyPackageUsagesCollector.java

示例3: guessLanguageLevel

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@NotNull
public static LanguageLevel guessLanguageLevel(@NotNull Project project) {
  final ModuleManager moduleManager = ModuleManager.getInstance(project);
  if (moduleManager != null) {
    LanguageLevel maxLevel = null;
    for (Module projectModule : moduleManager.getModules()) {
      final Sdk sdk = PythonSdkType.findPythonSdk(projectModule);
      if (sdk != null) {
        final LanguageLevel level = PythonSdkType.getLanguageLevelForSdk(sdk);
        if (maxLevel == null || maxLevel.isOlderThan(level)) {
          maxLevel = level;
        }
      }
    }
    if (maxLevel != null) {
      return maxLevel;
    }
  }
  return LanguageLevel.getDefault();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyUtil.java

示例4: createCheckProcess

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
Process createCheckProcess(@NotNull final Project project, @NotNull final String executablePath) throws ExecutionException {
  final Sdk sdk = PythonSdkType.findPythonSdk(ModuleManager.getInstance(project).getModules()[0]);
  PyEduPluginConfigurator configurator = new PyEduPluginConfigurator();
  String testsFileName = configurator.getTestFileName();
  if (myTask instanceof TaskWithSubtasks) {
    testsFileName = FileUtil.getNameWithoutExtension(testsFileName);
    int index = ((TaskWithSubtasks)myTask).getActiveSubtaskIndex();
    testsFileName += EduNames.SUBTASK_MARKER + index + "." + FileUtilRt.getExtension(configurator.getTestFileName());
  }
  final File testRunner = new File(myTaskDir.getPath(), testsFileName);
  myCommandLine = new GeneralCommandLine();
  myCommandLine.withWorkDirectory(myTaskDir.getPath());
  final Map<String, String> env = myCommandLine.getEnvironment();

  final VirtualFile courseDir = project.getBaseDir();
  if (courseDir != null) {
    env.put(PYTHONPATH, courseDir.getPath());
  }
  if (sdk != null) {
    String pythonPath = sdk.getHomePath();
    if (pythonPath != null) {
      myCommandLine.setExePath(pythonPath);
      myCommandLine.addParameter(testRunner.getPath());
      myCommandLine.addParameter(FileUtil.toSystemDependentName(executablePath));
      return myCommandLine.createProcess();
    }
  }
  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:30,代码来源:PyStudyTestRunner.java

示例5: getProjectUsages

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) throws CollectUsagesException {
  Set<UsageDescriptor> result = new HashSet<UsageDescriptor>();
  for(Module m: ModuleManager.getInstance(project).getModules()) {
    Sdk pythonSdk = PythonSdkType.findPythonSdk(m);
    if (pythonSdk != null) {
      String versionString = pythonSdk.getVersionString();
      if (versionString != null) {
        result.add(new UsageDescriptor(versionString, 1));
      }
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PyInterpreterUsagesCollector.java

示例6: createCheckProcess

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public Process createCheckProcess(@NotNull final Project project, @NotNull final String executablePath) throws ExecutionException {
  final Sdk sdk = PythonSdkType.findPythonSdk(ModuleManager.getInstance(project).getModules()[0]);
  Course course = myTask.getLesson().getCourse();
  StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
  if (manager == null) {
    LOG.info("Language manager is null for " + course.getLanguageById().getDisplayName());
    return null;
  }
  final File testRunner = new File(myTaskDir.getPath(), manager.getTestFileName());
  final GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.withWorkDirectory(myTaskDir.getPath());
  final Map<String, String> env = commandLine.getEnvironment();

  final VirtualFile courseDir = project.getBaseDir();
  if (courseDir != null) {
    env.put(PYTHONPATH, courseDir.getPath());
  }
  if (sdk != null) {
    String pythonPath = sdk.getHomePath();
    if (pythonPath != null) {
      commandLine.setExePath(pythonPath);
      commandLine.addParameter(testRunner.getPath());
      File resourceFile = new File(course.getCourseDirectory());
      commandLine.addParameter(resourceFile.getPath());
      commandLine.addParameter(FileUtil.toSystemDependentName(executablePath));
      return commandLine.createProcess();
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:PyStudyTestRunner.java

示例7: getValidModules

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public static List<Module> getValidModules(Project project) {
  final Module[] modules = ModuleManager.getInstance(project).getModules();
  List<Module> result = Lists.newArrayList();
  for (Module module : modules) {
    if (PythonSdkType.findPythonSdk(module) != null) {
      result.add(module);
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:AbstractPythonRunConfiguration.java

示例8: initExtra

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public void initExtra(@NotNull Project project, @NotNull MessageBus bus, @NotNull Engine languageLevelUpdater) {
  final Module[] modules = ModuleManager.getInstance(project).getModules();
  Set<Sdk> usedSdks = new HashSet<Sdk>();
  for (Module module : modules) {
    if (isPythonModule(module)) {
      final Sdk sdk = PythonSdkType.findPythonSdk(module);
      myModuleSdks.put(module, sdk);
      if (sdk != null && !usedSdks.contains(sdk)) {
        usedSdks.add(sdk);
        updateSdkLanguageLevel(project, sdk);
      }
    }
  }
  project.putUserData(PYTHON_LANGUAGE_LEVEL, PyUtil.guessLanguageLevel(project));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PythonLanguageLevelPusher.java

示例9: getPythonSdk

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
/** Find a python SDK associated with a blaze project, or its workspace module. */
@Nullable
public static Sdk getPythonSdk(Project project) {
  Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
  if (projectSdk != null && projectSdk.getSdkType() instanceof PythonSdkType) {
    return projectSdk;
  }
  // look for a SDK associated with a python facet instead.
  return PythonSdkType.findPythonSdk(
      ModuleManager.getInstance(project)
          .findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME));
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:13,代码来源:PySdkUtils.java

示例10: isConfigurationFromContext

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@Override
public boolean isConfigurationFromContext(AbstractPythonTestRunConfiguration configuration, ConfigurationContext context) {
  final Location location = context.getLocation();
  if (location == null) return false;
  if (!(configuration instanceof PyTestRunConfiguration)) return false;
  final PsiElement element = location.getPsiElement();

  final PsiFileSystemItem file = element instanceof PsiDirectory ? (PsiDirectory)element : element.getContainingFile();
  if (file == null) return false;
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return false;

  if (file instanceof PyFile || file instanceof PsiDirectory) {
    final List<PyStatement> testCases = PyTestUtil.getPyTestCasesFromFile(file);
    if (testCases.isEmpty()) return false;
  } else return false;

  final Sdk sdk = PythonSdkType.findPythonSdk(context.getModule());
  if (sdk == null) return false;
  final String keywords = getKeywords(element, sdk);
  final String scriptName = ((PyTestRunConfiguration)configuration).getTestToRun();
  final String workingDirectory = configuration.getWorkingDirectory();
  final String path = virtualFile.getPath();
  final boolean isTestFileEquals = scriptName.equals(path) ||
                                   path.equals(new File(workingDirectory, scriptName).getAbsolutePath());

  final String configurationKeywords = ((PyTestRunConfiguration)configuration).getKeywords();
  return isTestFileEquals && (configurationKeywords.equals(keywords) ||
                              StringUtil.isEmptyOrSpaces(((PyTestRunConfiguration)configuration).getKeywords()) && keywords == null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:PyTestConfigurationProducer.java

示例11: visitPyFile

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@Override
public void visitPyFile(PyFile node) {
  final Module module = ModuleUtilCore.findModuleForPsiElement(node);
  if (module != null) {
    if (isRunningPackagingTasks(module)) {
      return;
    }
    final Sdk sdk = PythonSdkType.findPythonSdk(module);
    if (sdk != null) {
      final List<PyRequirement> unsatisfied = findUnsatisfiedRequirements(module, sdk, myIgnoredPackages);
      if (unsatisfied != null && !unsatisfied.isEmpty()) {
        final boolean plural = unsatisfied.size() > 1;
        String msg = String.format("Package requirement%s %s %s not satisfied",
                                   plural ? "s" : "",
                                   requirementsToString(unsatisfied),
                                   plural ? "are" : "is");
        final Set<String> unsatisfiedNames = new HashSet<String>();
        for (PyRequirement req : unsatisfied) {
          unsatisfiedNames.add(req.getName());
        }
        final List<LocalQuickFix> quickFixes = new ArrayList<LocalQuickFix>();
        quickFixes.add(new PyInstallRequirementsFix(null, module, sdk, unsatisfied));
        quickFixes.add(new IgnoreRequirementFix(unsatisfiedNames));
        registerProblem(node, msg,
                        ProblemHighlightType.GENERIC_ERROR_OR_WARNING, null,
                        quickFixes.toArray(new LocalQuickFix[quickFixes.size()]));
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:PyPackageRequirementsInspection.java

示例12: setupConfigurationFromContext

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@Override
protected boolean setupConfigurationFromContext(AbstractPythonTestRunConfiguration configuration,
                                                ConfigurationContext context,
                                                Ref<PsiElement> sourceElement) {
  final PsiElement element = sourceElement.get();
  final Module module = ModuleUtilCore.findModuleForPsiElement(element);
  if (!(configuration instanceof PyTestRunConfiguration)) return false;
  if (module == null) return false;
  if (!(TestRunnerService.getInstance(module).getProjectConfiguration().equals(
         PythonTestConfigurationsModel.PY_TEST_NAME))) return false;

  final PsiFileSystemItem file = element instanceof PsiDirectory ? (PsiDirectory)element : element.getContainingFile();
  if (file == null) return false;
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return false;

  if (file instanceof PyFile || file instanceof PsiDirectory) {
    final List<PyStatement> testCases = PyTestUtil.getPyTestCasesFromFile(file);
    if (testCases.isEmpty()) return false;
  } else return false;

  final Sdk sdk = PythonSdkType.findPythonSdk(context.getModule());
  if (sdk == null) return false;

  configuration.setUseModuleSdk(true);
  configuration.setModule(ModuleUtilCore.findModuleForPsiElement(element));
  ((PyTestRunConfiguration)configuration).setTestToRun(virtualFile.getPath());

  final String keywords = getKeywords(element, sdk);
  if (keywords != null) {
    ((PyTestRunConfiguration)configuration).useKeyword(true);
    ((PyTestRunConfiguration)configuration).setKeywords(keywords);
    configuration.setName("py.test in " + keywords);
  }
  else
    configuration.setName("py.test in " + file.getName());
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:PyTestConfigurationProducer.java

示例13: InstallAndImportQuickFix

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public InstallAndImportQuickFix(@NotNull final String packageName,
                                @Nullable final String asName,
                                @NotNull final PyElement node) {
  myPackageName = packageName;
  myAsName = asName;
  myNode = SmartPointerManager.getInstance(node.getProject()).createSmartPsiElementPointer(node, node.getContainingFile());
  myModule = ModuleUtilCore.findModuleForPsiElement(node);
  mySdk = PythonSdkType.findPythonSdk(myModule);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PyPackageRequirementsInspection.java

示例14: getSdkSelected

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@Nullable
private Sdk getSdkSelected() {
  String sdkHome = getSdkHome();
  if (StringUtil.isEmptyOrSpaces(sdkHome)) {
    final Sdk projectJdk = PythonSdkType.findPythonSdk(getModule());
    if (projectJdk != null) {
      sdkHome = projectJdk.getHomePath();
    }
  }

  return PythonSdkType.findSdkByPath(sdkHome);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:PyIdeCommonOptionsForm.java

示例15: isAvailable

import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
protected boolean isAvailable(@NotNull final Location location) {
  final PsiElement element = location.getPsiElement();
  Module module = location.getModule();
  if (module == null) module = ModuleUtilCore.findModuleForPsiElement(element);

  final Sdk sdk = PythonSdkType.findPythonSdk(module);
  return module != null && TestRunnerService.getInstance(module).getProjectConfiguration().equals(
    PythonTestConfigurationsModel.PYTHONS_ATTEST_NAME) && sdk != null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PythonAtTestConfigurationProducer.java


注:本文中的com.jetbrains.python.sdk.PythonSdkType.findPythonSdk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。