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

Add environment variables (run configuration) support for the PyCharm Community & Professional #13

Merged
merged 2 commits into from
Aug 3, 2024
Merged
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
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@

## [Unreleased]

## [1.3.0] - 2024-08-03

### Added

- Add environment variables (run configuration) support for the PyCharm Community & Professional

## [1.2.1] - 2024-07-24

### Added

- Remove screenshots from plugin.xml. (JetBrains Marketplace guidelines)

## [1.2.0] - 2024-07-21

### Added

- Add support for the Go SDK (GOROOT) integration from mise tools.

## [1.1.0] - 2024-07-20
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ 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
- **Environment Variables**: Set environment variables for your run configurations from mise config files.
- **JDK Integration**: Set JDK from mise config files.
- **Go SDK Integration**: Set Go SDK (GOROOT) from mise config files.


<!-- Plugin description end -->

### Screenshots
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dependencies {
implementation(project(":mise-products-gradle"))
implementation(project(":mise-products-goland"))
implementation(project(":mise-products-nodejs"))
implementation(project(":mise-products-pythonid"))
implementation(project(":mise-products-pythoncore"))
}

// Set the JVM language level used to build the project.
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 = 1.2.1
pluginVersion = 1.3.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 @@ -6,10 +6,16 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project

object Notification {
fun notify(content :String, type: NotificationType, project: Project? = null) {
val notification = NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(content, type)
fun notify(
content: String,
type: NotificationType,
project: Project? = null,
) {
val notification =
NotificationGroupManager
.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(content, type)

notification.icon = PluginIcons.Default
notification.notify(project)
Expand Down
19 changes: 19 additions & 0 deletions modules/products/pythoncore/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fun properties(key: String) = project.findProperty(key).toString()

plugins {
id("org.jetbrains.intellij")
alias(libs.plugins.kotlin) // Kotlin support
}

// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
version.set(properties("platformVersion"))
type.set("PC")

// Plugin Dependencies
plugins.set(listOf("PythonCore"))
}

dependencies {
implementation(project(":mise-core"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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 PythonCoreRunConfigurationExtension :
PythonRunConfigurationExtension(),
PythonCommandLineTargetEnvironmentProvider {

Check warning on line 21 in modules/products/pythoncore/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonCoreRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.jetbrains.python.run.target.PythonCommandLineTargetEnvironmentProvider' is marked unstable with @ApiStatus.Experimental
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)

Check notice on line 51 in modules/products/pythoncore/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonCoreRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Accessor call that can be replaced with property access syntax

Use of getter method instead of property access syntax

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(

Check warning on line 65 in modules/products/pythoncore/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonCoreRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

Overridden method 'extendTargetEnvironment(com.intellij.openapi.project.Project, com.jetbrains.python.run.target.HelpersAwareTargetEnvironmentRequest, com.jetbrains.python.run.PythonExecution, com.jetbrains.python.run.PythonRunParams)' is declared in unstable 'com.jetbrains.python.run.target.PythonCommandLineTargetEnvironmentProvider' marked with @ApiStatus.Experimental
project: Project,
helpersAwareTargetRequest: HelpersAwareTargetEnvironmentRequest,
pythonExecution: PythonExecution,

Check warning on line 68 in modules/products/pythoncore/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonCoreRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.jetbrains.python.run.PythonExecution' is marked unstable with @ApiStatus.Experimental
runParams: PythonRunParams,
) {
if (runParams is AbstractPythonRunConfiguration<*> &&
RunConfigurationSettingsEditor.isMiseEnabled(runParams)
) {
runParams.setEnvs(MiseCmd.loadEnv(runParams.workingDirectory))
}
}
}
19 changes: 19 additions & 0 deletions modules/products/pythonid/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fun properties(key: String) = project.findProperty(key).toString()

plugins {
id("org.jetbrains.intellij")
alias(libs.plugins.kotlin) // Kotlin support
}

// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
version.set(properties("platformVersion"))
type.set("PY")

// Plugin Dependencies
plugins.set(listOf("Pythonid"))
}

dependencies {
implementation(project(":mise-core"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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 PythonidRunConfigurationExtension :
PythonRunConfigurationExtension(),
PythonCommandLineTargetEnvironmentProvider {

Check warning on line 21 in modules/products/pythonid/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonidRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.jetbrains.python.run.target.PythonCommandLineTargetEnvironmentProvider' is marked unstable with @ApiStatus.Experimental
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)

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(

Check warning on line 64 in modules/products/pythonid/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonidRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

Overridden method 'extendTargetEnvironment(com.intellij.openapi.project.Project, com.jetbrains.python.run.target.HelpersAwareTargetEnvironmentRequest, com.jetbrains.python.run.PythonExecution, com.jetbrains.python.run.PythonRunParams)' is declared in unstable 'com.jetbrains.python.run.target.PythonCommandLineTargetEnvironmentProvider' marked with @ApiStatus.Experimental
project: Project,
helpersAwareTargetRequest: HelpersAwareTargetEnvironmentRequest,
pythonExecution: PythonExecution,

Check warning on line 67 in modules/products/pythonid/src/main/kotlin/com/github/l34130/mise/runconfigs/PythonidRunConfigurationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.jetbrains.python.run.PythonExecution' is marked unstable with @ApiStatus.Experimental
runParams: PythonRunParams,
) {
if (runParams is AbstractPythonRunConfiguration<*> &&
RunConfigurationSettingsEditor.isMiseEnabled(runParams)
) {
runParams.setEnvs(MiseCmd.loadEnv(runParams.workingDirectory))
}
}
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ include(
"modules/products/gradle",
"modules/products/goland",
"modules/products/nodejs",
"modules/products/pythonid",
"modules/products/pythoncore",
)

rootProject.name = "mise"
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/mise-pythoncore.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.PythonCoreRunConfigurationExtension"
id="misePythonCore"/>
<pythonCommandLineTargetEnvironmentProvider implementation="com.github.l34130.mise.runconfigs.PythonCoreRunConfigurationExtension"/>
</extensions>
</idea-plugin>
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/mise-pythonid.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.PythonidRunConfigurationExtension"
id="misePythonid"/>
<pythonCommandLineTargetEnvironmentProvider implementation="com.github.l34130.mise.runconfigs.PythonidRunConfigurationExtension"/>
</extensions>
</idea-plugin>
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
<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-javascript.xml">JavaScript</depends>
<depends optional="true" config-file="mise-pythonid.xml">Pythonid</depends>
<depends optional="true" config-file="mise-pythoncore.xml">PythonCore</depends>
</idea-plugin>
Loading