generated from JetBrains/intellij-platform-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType | ||
|
||
fun properties(key: String) = project.findProperty(key).toString() | ||
|
||
plugins { | ||
id("org.jetbrains.intellij.platform.module") | ||
alias(libs.plugins.kotlin) // Kotlin support | ||
} | ||
|
||
dependencies { | ||
implementation(project(":mise-core")) | ||
|
||
// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin | ||
intellijPlatform { | ||
create(IntelliJPlatformType.PyCharmCommunity, properties("platformVersion")) | ||
|
||
bundledPlugins("PythonCore") | ||
|
||
jetbrainsRuntime() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...in/kotlin/com/github/l34130/mise/python/run/PythonCommandLineTargetEnvironmentProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.github.l34130.mise.python.run | ||
|
||
import com.github.l34130.mise.core.command.MiseCommandLineHelper | ||
import com.github.l34130.mise.core.command.MiseCommandLineNotFoundException | ||
import com.github.l34130.mise.core.notification.MiseNotificationServiceUtils | ||
import com.github.l34130.mise.core.run.MiseRunConfigurationSettingsEditor | ||
import com.github.l34130.mise.core.setting.MiseSettings | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.Project | ||
import com.jetbrains.python.run.AbstractPythonRunConfiguration | ||
import com.jetbrains.python.run.PythonExecution | ||
import com.jetbrains.python.run.PythonRunParams | ||
import com.jetbrains.python.run.target.HelpersAwareTargetEnvironmentRequest | ||
import com.jetbrains.python.run.target.PythonCommandLineTargetEnvironmentProvider | ||
|
||
@Suppress("UnstableApiUsage") | ||
class PythonCommandLineTargetEnvironmentProvider : PythonCommandLineTargetEnvironmentProvider { | ||
override fun extendTargetEnvironment( | ||
project: Project, | ||
helpersAwareTargetRequest: HelpersAwareTargetEnvironmentRequest, | ||
pythonExecution: PythonExecution, | ||
runParams: PythonRunParams, | ||
) { | ||
if (runParams is AbstractPythonRunConfiguration<*>) { | ||
val projectState = project.service<MiseSettings>().state | ||
val runConfigState = MiseRunConfigurationSettingsEditor.getMiseRunConfigurationState(runParams) | ||
|
||
val (workDir, configEnvironment) = | ||
when { | ||
projectState.useMiseDirEnv -> project.basePath to projectState.miseConfigEnvironment | ||
runConfigState?.useMiseDirEnv == true -> { | ||
val pythonWorkDir = runParams.workingDirectory ?: runParams.projectPathOnTarget | ||
(pythonWorkDir ?: runParams.project.basePath) to runConfigState.miseConfigEnvironment | ||
} | ||
else -> null to null | ||
} | ||
|
||
val envVars = | ||
MiseCommandLineHelper | ||
.getEnvVars(workDir, configEnvironment) | ||
.fold( | ||
onSuccess = { envVars -> envVars }, | ||
onFailure = { | ||
if (it !is MiseCommandLineNotFoundException) { | ||
MiseNotificationServiceUtils.notifyException("Failed to load environment variables", it) | ||
} | ||
emptyMap() | ||
}, | ||
) | ||
|
||
envVars.forEach { (key, value) -> | ||
pythonExecution.addEnvironmentVariable(key, value) | ||
} | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...harm/src/main/kotlin/com/github/l34130/mise/python/run/PythonRunConfigurationExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.github.l34130.mise.python.run | ||
|
||
import com.github.l34130.mise.core.command.MiseCommandLineHelper | ||
import com.github.l34130.mise.core.command.MiseCommandLineNotFoundException | ||
import com.github.l34130.mise.core.notification.MiseNotificationServiceUtils | ||
import com.github.l34130.mise.core.run.MiseRunConfigurationSettingsEditor | ||
import com.github.l34130.mise.core.setting.MiseSettings | ||
import com.intellij.execution.configurations.GeneralCommandLine | ||
import com.intellij.execution.configurations.RunnerSettings | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.options.SettingsEditor | ||
import com.jetbrains.python.run.AbstractPythonRunConfiguration | ||
import com.jetbrains.python.run.PythonRunConfigurationExtension | ||
import org.jdom.Element | ||
|
||
class PythonRunConfigurationExtension : PythonRunConfigurationExtension() { | ||
override fun isApplicableFor(runConfiguration: AbstractPythonRunConfiguration<*>): Boolean = true | ||
|
||
override fun isEnabledFor( | ||
runConfiguration: AbstractPythonRunConfiguration<*>, | ||
runnerSettings: RunnerSettings?, | ||
): Boolean = true | ||
|
||
override fun writeExternal( | ||
runConfiguration: AbstractPythonRunConfiguration<*>, | ||
element: Element, | ||
) { | ||
MiseRunConfigurationSettingsEditor.writeExternal(runConfiguration, element) | ||
} | ||
|
||
override fun readExternal( | ||
runConfiguration: AbstractPythonRunConfiguration<*>, | ||
element: Element, | ||
) { | ||
MiseRunConfigurationSettingsEditor.readExternal(runConfiguration, element) | ||
} | ||
|
||
override fun getEditorTitle(): String = MiseRunConfigurationSettingsEditor.EDITOR_TITLE | ||
|
||
override fun <P : AbstractPythonRunConfiguration<*>> createEditor(configuration: P): SettingsEditor<P> = | ||
MiseRunConfigurationSettingsEditor(configuration.project) | ||
|
||
override fun patchCommandLine( | ||
runConfiguration: AbstractPythonRunConfiguration<*>, | ||
runnerSettings: RunnerSettings?, | ||
cmdLine: GeneralCommandLine, | ||
runnerId: String, | ||
) { | ||
val project = runConfiguration.project | ||
val projectState = project.service<MiseSettings>().state | ||
val runConfigState = MiseRunConfigurationSettingsEditor.getMiseRunConfigurationState(runConfiguration) | ||
|
||
val (workDir, configEnvironment) = | ||
when { | ||
projectState.useMiseDirEnv -> project.basePath to projectState.miseConfigEnvironment | ||
runConfigState?.useMiseDirEnv == true -> { | ||
val pythonWorkDir = runConfiguration.workingDirectory ?: runConfiguration.projectPathOnTarget | ||
(pythonWorkDir ?: runConfiguration.project.basePath) to runConfigState.miseConfigEnvironment | ||
} | ||
else -> null to null | ||
} | ||
|
||
val envVars = | ||
MiseCommandLineHelper | ||
.getEnvVars(workDir, configEnvironment) | ||
.fold( | ||
onSuccess = { envVars -> envVars }, | ||
onFailure = { | ||
if (it !is MiseCommandLineNotFoundException) { | ||
MiseNotificationServiceUtils.notifyException("Failed to load environment variables", it) | ||
} | ||
emptyMap() | ||
}, | ||
) | ||
|
||
cmdLine.withEnvironment(envVars) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<idea-plugin require-restart="false"> | ||
<extensions defaultExtensionNs="Pythonid"> | ||
<runConfigurationExtension implementation="com.github.l34130.mise.python.run.PythonRunConfigurationExtension" | ||
id="misePython"/> | ||
<pythonCommandLineTargetEnvironmentProvider implementation="com.github.l34130.mise.python.run.PythonCommandLineTargetEnvironmentProvider"/> | ||
</extensions> | ||
</idea-plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters