use of com.jetbrains.python.documentation.PyDocumentationSettings in project intellij-community by JetBrains.
the class DocStringUtil method ensureNotPlainDocstringFormatForFile.
private static boolean ensureNotPlainDocstringFormatForFile(@NotNull PsiFile file, @NotNull Module module) {
final PyDocumentationSettings settings = PyDocumentationSettings.getInstance(module);
if (settings.isPlain(file)) {
final List<String> values = DocStringFormat.ALL_NAMES_BUT_PLAIN;
final int i = Messages.showChooseDialog("Docstring format:", "Select Docstring Type", ArrayUtil.toStringArray(values), values.get(0), null);
if (i < 0) {
return false;
}
settings.setFormat(DocStringFormat.fromNameOrPlain(values.get(i)));
}
return true;
}
use of com.jetbrains.python.documentation.PyDocumentationSettings in project intellij-community by JetBrains.
the class PyIntegratedToolsProjectConfigurator method updateIntegratedTools.
private static void updateIntegratedTools(final Module module, final int delay) {
ModalityState modality = ModalityState.current();
final PyDocumentationSettings docSettings = PyDocumentationSettings.getInstance(module);
AppExecutorUtil.getAppScheduledExecutorService().schedule(() -> ApplicationManager.getApplication().invokeLater(() -> {
LOG.debug("Integrated tools configurator has started");
if (module.isDisposed())
return;
@NotNull DocStringFormat docFormat = DocStringFormat.PLAIN;
//check setup.py
@NotNull String testRunner = detectTestRunnerFromSetupPy(module);
if (!testRunner.isEmpty()) {
LOG.debug("Test runner '" + testRunner + "' was discovered from setup.py in the module '" + module.getModuleFilePath() + "'");
}
//try to find test_runner import
final String extension = PythonFileType.INSTANCE.getDefaultExtension();
// Module#getModuleScope() and GlobalSearchScope#getModuleScope() search only in source roots
final GlobalSearchScope searchScope = module.getModuleScope();
final Collection<VirtualFile> pyFiles = FilenameIndex.getAllFilesByExt(module.getProject(), extension, searchScope);
for (VirtualFile file : pyFiles) {
if (file.getName().startsWith("test")) {
if (testRunner.isEmpty()) {
//find test runner import
testRunner = checkImports(file, module);
if (!testRunner.isEmpty()) {
LOG.debug("Test runner '" + testRunner + "' was detected from imports in the file '" + file.getPath() + "'");
}
}
} else if (docFormat == DocStringFormat.PLAIN) {
// detect docstring type
docFormat = checkDocstring(file, module);
if (docFormat != DocStringFormat.PLAIN) {
LOG.debug("Docstring format '" + docFormat + "' was detected from content of the file '" + file.getPath() + "'");
}
}
if (!testRunner.isEmpty() && docFormat != DocStringFormat.PLAIN) {
break;
}
}
// Check test runners available in the module SDK
if (testRunner.isEmpty()) {
//check if installed in sdk
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk != null && sdk.getSdkType() instanceof PythonSdkType) {
final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk);
if (packages != null) {
final boolean nose = PyPackageUtil.findPackage(packages, PyNames.NOSE_TEST) != null;
final boolean pytest = PyPackageUtil.findPackage(packages, PyNames.PY_TEST) != null;
if (nose)
testRunner = PythonTestConfigurationsModel.PYTHONS_NOSETEST_NAME;
else if (pytest)
testRunner = PythonTestConfigurationsModel.PY_TEST_NAME;
if (!testRunner.isEmpty()) {
LOG.debug("Test runner '" + testRunner + "' was detected from SDK " + sdk);
}
}
}
}
final TestRunnerService runnerService = TestRunnerService.getInstance(module);
if (runnerService != null) {
if (testRunner.isEmpty()) {
runnerService.setProjectConfiguration(PythonTestConfigurationsModel.PYTHONS_UNITTEST_NAME);
} else {
runnerService.setProjectConfiguration(testRunner);
LOG.info("Test runner '" + testRunner + "' was detected by project configurator");
}
}
// Documentation settings should have meaningful default already
if (docFormat != DocStringFormat.PLAIN) {
docSettings.setFormat(docFormat);
LOG.info("Docstring format '" + docFormat + "' was detected by project configurator");
}
}, modality), delay, TimeUnit.MILLISECONDS);
}
use of com.jetbrains.python.documentation.PyDocumentationSettings in project intellij-community by JetBrains.
the class PyTestCase method runWithDocStringFormat.
protected void runWithDocStringFormat(@NotNull DocStringFormat format, @NotNull Runnable runnable) {
final PyDocumentationSettings settings = PyDocumentationSettings.getInstance(myFixture.getModule());
final DocStringFormat oldFormat = settings.getFormat();
settings.setFormat(format);
try {
runnable.run();
} finally {
settings.setFormat(oldFormat);
}
}
use of com.jetbrains.python.documentation.PyDocumentationSettings in project intellij-community by JetBrains.
the class PyQuickDocTest method tearDown.
@Override
public void tearDown() throws Exception {
final PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getModule());
documentationSettings.setFormat(myFormat);
super.tearDown();
}
use of com.jetbrains.python.documentation.PyDocumentationSettings in project intellij-community by JetBrains.
the class PySmartEnterTest method testDocTypeRType.
public void testDocTypeRType() {
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
boolean oldStubOnEnter = codeInsightSettings.JAVADOC_STUB_ON_ENTER;
codeInsightSettings.JAVADOC_STUB_ON_ENTER = true;
PyCodeInsightSettings pyCodeInsightSettings = PyCodeInsightSettings.getInstance();
boolean oldInsertType = pyCodeInsightSettings.INSERT_TYPE_DOCSTUB;
pyCodeInsightSettings.INSERT_TYPE_DOCSTUB = true;
PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getModule());
documentationSettings.setFormat(DocStringFormat.EPYTEXT);
try {
doTest();
} finally {
documentationSettings.setFormat(DocStringFormat.PLAIN);
codeInsightSettings.JAVADOC_STUB_ON_ENTER = oldStubOnEnter;
pyCodeInsightSettings.INSERT_TYPE_DOCSTUB = oldInsertType;
}
}
Aggregations