[qodana] QD-9527 Enabled Poetry SDK creation for Poetry projects in headless mode

GitOrigin-RevId: edaab8de048359a95a197989fb2c53068dd21f3e
This commit is contained in:
Andrei Iurko
2024-07-22 09:37:49 +03:00
committed by intellij-monorepo-bot
parent 29ca865bc6
commit f65c970d2d
3 changed files with 21 additions and 6 deletions

View File

@@ -78,10 +78,12 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator {
} }
private fun findExtension(module: Module): PyProjectSdkConfigurationExtension? { private fun findExtension(module: Module): PyProjectSdkConfigurationExtension? {
return if (!module.project.isTrusted() || ApplicationManager.getApplication().let { it.isHeadlessEnvironment || it.isUnitTestMode }) { return if (!module.project.isTrusted() || ApplicationManager.getApplication().isUnitTestMode) {
null null
} }
else PyProjectSdkConfigurationExtension.EP_NAME.findFirstSafe { it.getIntention(module) != null } else PyProjectSdkConfigurationExtension.EP_NAME.findFirstSafe {
it.getIntention(module) != null && (!ApplicationManager.getApplication().isHeadlessEnvironment || it.supportsHeadlessModel())
}
} }
fun configureSdk( fun configureSdk(

View File

@@ -45,6 +45,8 @@ class PyPoetrySdkConfiguration : PyProjectSdkConfigurationExtension {
override fun createAndAddSdkForInspection(module: Module): Sdk? = createAndAddSDk(module, true) override fun createAndAddSdkForInspection(module: Module): Sdk? = createAndAddSDk(module, true)
override fun supportsHeadlessModel(): Boolean = true
private fun createAndAddSDk(module: Module, inspection: Boolean): Sdk? { private fun createAndAddSDk(module: Module, inspection: Boolean): Sdk? {
val poetryEnvExecutable = askForEnvData(module, inspection) ?: return null val poetryEnvExecutable = askForEnvData(module, inspection) ?: return null
PropertiesComponent.getInstance().poetryPath = poetryEnvExecutable.poetryPath.pathString PropertiesComponent.getInstance().poetryPath = poetryEnvExecutable.poetryPath.pathString
@@ -53,10 +55,14 @@ class PyPoetrySdkConfiguration : PyProjectSdkConfigurationExtension {
private fun askForEnvData(module: Module, inspection: Boolean): PyAddNewPoetryFromFilePanel.Data? { private fun askForEnvData(module: Module, inspection: Boolean): PyAddNewPoetryFromFilePanel.Data? {
val poetryExecutable = getPoetryExecutable() val poetryExecutable = getPoetryExecutable()
val isHeadlessEnv = ApplicationManager.getApplication().isHeadlessEnvironment
if (inspection && validatePoetryExecutable(poetryExecutable) == null) { if ((inspection || isHeadlessEnv) && validatePoetryExecutable(poetryExecutable) == null) {
return PyAddNewPoetryFromFilePanel.Data(poetryExecutable!!) return PyAddNewPoetryFromFilePanel.Data(poetryExecutable!!)
} }
else if (isHeadlessEnv) {
return null
}
var permitted = false var permitted = false
var envData: PyAddNewPoetryFromFilePanel.Data? = null var envData: PyAddNewPoetryFromFilePanel.Data? = null
@@ -152,4 +158,4 @@ class PyPoetrySdkConfiguration : PyProjectSdkConfigurationExtension {
override fun doValidateAll(): List<ValidationInfo> = panel.validateAll() override fun doValidateAll(): List<ValidationInfo> = panel.validateAll()
} }
} }

View File

@@ -10,9 +10,10 @@ import org.jetbrains.annotations.ApiStatus
/** /**
* Used on directory opening with an attempt to configure suitable Python interpreter * Used on directory opening with an attempt to configure suitable Python interpreter
* (mentioned below as sdk configurator, ignored in headless mode). * (mentioned below as sdk configurator).
* *
* Used with an attempt to suggest suitable Python interpreter if no interpreter is specified. * Used with an attempt to suggest suitable Python interpreter
* or try setup and register it in case of headless mode if no interpreter is specified.
*/ */
@ApiStatus.Experimental @ApiStatus.Experimental
interface PyProjectSdkConfigurationExtension { interface PyProjectSdkConfigurationExtension {
@@ -60,4 +61,10 @@ interface PyProjectSdkConfigurationExtension {
*/ */
@RequiresBackgroundThread @RequiresBackgroundThread
fun createAndAddSdkForInspection(module: Module): Sdk? fun createAndAddSdkForInspection(module: Module): Sdk?
/**
* If headless supported implementation is responsible for interpreter setup and registration
* for [createAndAddSdkForConfigurator] method in IDE without an additional user input.
*/
fun supportsHeadlessModel(): Boolean = false
} }