From d3d5a9e21c2f0a292c40981ba91d8b7f43db1e63 Mon Sep 17 00:00:00 2001 From: Cooper Oh Date: Sun, 11 Aug 2024 11:44:27 +0900 Subject: [PATCH] wip --- CHANGELOG.md | 9 +- README.md | 1 + build.gradle.kts | 1 + gradle.properties | 2 +- .../ui/RunConfigurationSettingsEditor.kt | 18 ++-- modules/products/pycharm/build.gradle.kts | 19 +++++ .../PyCharmRunConfigurationExtension.kt | 82 +++++++++++++++++++ settings.gradle.kts | 1 + src/main/resources/META-INF/mise-pycharm.xml | 7 ++ src/main/resources/META-INF/plugin.xml | 5 +- 10 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 modules/products/pycharm/build.gradle.kts create mode 100644 modules/products/pycharm/src/main/kotlin/com/github/l34130/mise/runconfigs/PyCharmRunConfigurationExtension.kt create mode 100644 src/main/resources/META-INF/mise-pycharm.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index e604e8f4..e279ff7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ ## [Unreleased] +## [2.1.0] - 2024-08-11 + +### Added + +- Add run configuration support for the PyCharm Community & Professional + ## [2.0.0] - 2024-08-03 ### Changed @@ -47,7 +53,8 @@ - Support JDK integration from mise tools. -[Unreleased]: https://github.com/134130/intellij-mise/compare/v2.0.0...HEAD +[Unreleased]: https://github.com/134130/intellij-mise/compare/v2.1.0...HEAD +[2.1.0]: https://github.com/134130/intellij-mise/compare/v2.0.0...v2.1.0 [2.0.0]: https://github.com/134130/intellij-mise/compare/v1.3.0...v2.0.0 [1.3.0]: https://github.com/134130/intellij-mise/compare/v1.2.1...v1.3.0 [1.2.1]: https://github.com/134130/intellij-mise/compare/v1.2.0...v1.2.1 diff --git a/README.md b/README.md index ad51a759..9ddb408f 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ from mise config files. see: **[mise-en-place](https://mise.jdx.dev)** - **IntelliJ IDEA** - **GoLand** - **WebStorm** +- **PyCharm** Community & Professional - _Submit issue if you need other IDE_ ### Features diff --git a/build.gradle.kts b/build.gradle.kts index 4abe09dc..13edfc88 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,6 +33,7 @@ dependencies { pluginModule(implementation(project(":mise-products-gradle"))) pluginModule(implementation(project(":mise-products-idea"))) pluginModule(implementation(project(":mise-products-nodejs"))) + pluginModule(implementation(project(":mise-products-pycharm"))) plugins(listOf()) diff --git a/gradle.properties b/gradle.properties index 4065dd8f..90b7410b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.github.l34130.mise pluginName = mise pluginRepositoryUrl = https://github.com/134130/intellij-mise # SemVer format -> https://semver.org -pluginVersion = 2.0.0 +pluginVersion = 2.1.0 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 223 diff --git a/modules/core/src/main/kotlin/com/github/l34130/mise/settings/ui/RunConfigurationSettingsEditor.kt b/modules/core/src/main/kotlin/com/github/l34130/mise/settings/ui/RunConfigurationSettingsEditor.kt index 3931735c..b6564403 100644 --- a/modules/core/src/main/kotlin/com/github/l34130/mise/settings/ui/RunConfigurationSettingsEditor.kt +++ b/modules/core/src/main/kotlin/com/github/l34130/mise/settings/ui/RunConfigurationSettingsEditor.kt @@ -60,20 +60,20 @@ class RunConfigurationSettingsEditor>( private class RunConfigurationSettingsPanel>( private val configuration: T, - ) : JPanel() { + ) : JPanel(BorderLayout()) { val enableMiseCheckBox = JBCheckBox("Enable mise") init { - val p = panel { - row { - cell(enableMiseCheckBox).comment( - "Load environment variables from mise configuration file(s)", - ) + val p = + panel { + row { + cell(enableMiseCheckBox).comment( + "Load environment variables from mise configuration file(s)", + ) + } } - } - layout = BorderLayout() - add(p) + add(p, BorderLayout.NORTH) } var state: MiseSettings diff --git a/modules/products/pycharm/build.gradle.kts b/modules/products/pycharm/build.gradle.kts new file mode 100644 index 00000000..33e3f540 --- /dev/null +++ b/modules/products/pycharm/build.gradle.kts @@ -0,0 +1,19 @@ +import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType + +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, providers.gradleProperty("platformVersion"), false) + + bundledPlugins("PythonCore") + + instrumentationTools() + } +} diff --git a/modules/products/pycharm/src/main/kotlin/com/github/l34130/mise/runconfigs/PyCharmRunConfigurationExtension.kt b/modules/products/pycharm/src/main/kotlin/com/github/l34130/mise/runconfigs/PyCharmRunConfigurationExtension.kt new file mode 100644 index 00000000..b4a46530 --- /dev/null +++ b/modules/products/pycharm/src/main/kotlin/com/github/l34130/mise/runconfigs/PyCharmRunConfigurationExtension.kt @@ -0,0 +1,82 @@ +package com.github.l34130.mise.runconfigs + +import com.github.l34130.mise.commands.MiseCmd +import com.github.l34130.mise.notifications.Notification +import com.github.l34130.mise.settings.ui.RunConfigurationSettingsEditor +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.configurations.RunnerSettings +import com.intellij.notification.NotificationType +import com.intellij.openapi.options.SettingsEditor +import com.intellij.openapi.project.Project +import com.jetbrains.python.run.AbstractPythonRunConfiguration +import com.jetbrains.python.run.PythonExecution +import com.jetbrains.python.run.PythonRunConfigurationExtension +import com.jetbrains.python.run.PythonRunParams +import com.jetbrains.python.run.target.HelpersAwareTargetEnvironmentRequest +import com.jetbrains.python.run.target.PythonCommandLineTargetEnvironmentProvider +import org.jdom.Element + +class PyCharmRunConfigurationExtension : + PythonRunConfigurationExtension(), + PythonCommandLineTargetEnvironmentProvider { + override fun getEditorTitle(): String = RunConfigurationSettingsEditor.EDITOR_TITLE + + override fun

> createEditor(configuration: P): SettingsEditor

= + RunConfigurationSettingsEditor(configuration) + + override fun getSerializationId(): String = RunConfigurationSettingsEditor.SERIALIZATION_ID + + override fun readExternal( + runConfiguration: AbstractPythonRunConfiguration<*>, + element: Element, + ) { + RunConfigurationSettingsEditor.readExternal(runConfiguration, element) + } + + override fun writeExternal( + runConfiguration: AbstractPythonRunConfiguration<*>, + element: Element, + ) { + RunConfigurationSettingsEditor.writeExternal(runConfiguration, element) + } + + override fun patchCommandLine( + configuration: AbstractPythonRunConfiguration<*>, + runnerSettings: RunnerSettings?, + cmdLine: GeneralCommandLine, + runnerId: String, + ) { + Notification.notify("Patching command line for Pythonid run configuration", NotificationType.INFORMATION) + Notification.notify("${cmdLine.environment}", NotificationType.INFORMATION) + Notification.notify(configuration.getWorkingDirectorySafe(), NotificationType.INFORMATION) + + if (RunConfigurationSettingsEditor.isMiseEnabled(configuration)) { + cmdLine.environment.putAll(MiseCmd.loadEnv(configuration.workingDirectory)) + } + } + + override fun isApplicableFor(configuration: AbstractPythonRunConfiguration<*>): Boolean = true + + override fun isEnabledFor( + applicableConfiguration: AbstractPythonRunConfiguration<*>, + runnerSettings: RunnerSettings?, + ): Boolean = true + + override fun extendTargetEnvironment( + project: Project, + helpersAwareTargetRequest: HelpersAwareTargetEnvironmentRequest, + pythonExecution: PythonExecution, + runParams: PythonRunParams, + ) { + if (runParams is AbstractPythonRunConfiguration<*> && + RunConfigurationSettingsEditor.isMiseEnabled(runParams) + ) { + MiseCmd.loadEnv(runParams.workingDirectory).forEach { (k, v) -> + pythonExecution.addEnvironmentVariable(k, v) + } + runParams.getEnvs().forEach { (k, v) -> + pythonExecution.addEnvironmentVariable(k, v) + } + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 953b27e3..2854f23a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,6 +22,7 @@ include( "modules/products/gradle", "modules/products/goland", "modules/products/nodejs", + "modules/products/pycharm", ) rootProject.name = "mise" diff --git a/src/main/resources/META-INF/mise-pycharm.xml b/src/main/resources/META-INF/mise-pycharm.xml new file mode 100644 index 00000000..cf02ff65 --- /dev/null +++ b/src/main/resources/META-INF/mise-pycharm.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 0c984491..18626334 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -19,8 +19,9 @@ - com.intellij.java - com.intellij.gradle org.jetbrains.plugins.go + com.intellij.gradle + com.intellij.java JavaScript + com.intellij.modules.python