Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support run configuration for PyCharm Community & Professional #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ class RunConfigurationSettingsEditor<T : RunConfigurationBase<*>>(

private class RunConfigurationSettingsPanel<T : RunConfigurationBase<*>>(
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
Expand Down
19 changes: 19 additions & 0 deletions modules/products/pycharm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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 <P : AbstractPythonRunConfiguration<*>> createEditor(configuration: P): SettingsEditor<P> =
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)
}
}
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ include(
"modules/products/gradle",
"modules/products/goland",
"modules/products/nodejs",
"modules/products/pycharm",
)

rootProject.name = "mise"
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/mise-pycharm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<idea-plugin>
<extensions defaultExtensionNs="Pythonid">
<runConfigurationExtension implementation="com.github.l34130.mise.runconfigs.PyCharmRunConfigurationExtension"
id="misePyCharm"/>
<pythonCommandLineTargetEnvironmentProvider implementation="com.github.l34130.mise.runconfigs.PyCharmRunConfigurationExtension"/>
</extensions>
</idea-plugin>
5 changes: 3 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
</group>
</actions>

<depends optional="true" config-file="mise-idea.xml">com.intellij.java</depends>
<depends optional="true" config-file="mise-gradle.xml">com.intellij.gradle</depends>
<depends optional="true" config-file="mise-goland.xml">org.jetbrains.plugins.go</depends>
<depends optional="true" config-file="mise-gradle.xml">com.intellij.gradle</depends>
<depends optional="true" config-file="mise-idea.xml">com.intellij.java</depends>
<depends optional="true" config-file="mise-javascript.xml">JavaScript</depends>
<depends optional="true" config-file="mise-pycharm.xml">com.intellij.modules.python</depends>
</idea-plugin>
Loading