Skip to content

Commit

Permalink
Merge pull request #53 from JetBrains-Research/khbminus/envs
Browse files Browse the repository at this point in the history
Added support of environs to IDEA
  • Loading branch information
khbminus authored Mar 15, 2023
2 parents aabbd69 + ca172ec commit cb0c110
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions example/.run/example [main].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="example [main]" type="PaddleRunConfiguration" factoryName="Paddle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="CUSTOM_ENV" value="are supported" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="Paddle" />
<option name="scriptParameters" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="main" />
<option value="-Ppython.run.extraArgs=&quot;arg1 arg2 arg3&quot;" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<method v="2" />
</configuration>
</component>
2 changes: 2 additions & 0 deletions example/src/main/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sys
import os
from bugloc.app import Bar

if __name__ == '__main__':
print(sys.path)
print(sys.argv)
print(os.getenv('CUSTOM_ENV')) # You can find an example run configuration in .run folder
for i in range(100000000):
pass
print("Hello world!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class PythonScriptCommandLineStateProvider : PaddleTaskRunProfileStateProvider<R

val additionalArgsLine = (context.originalRunConfiguration as PaddleRunConfiguration).commandLine.tasksAndArguments.toList()
val additionalArgs = Paddle.parseCliOptions(additionalArgsLine)["extraArgs"]?.trim('"', '\'') ?: ""
val env: MutableMap<String, String> = context.originalRunConfiguration.settings.env.toMutableMap()
env["PYTHONPATH"] = env["PYTHONPATH"]?.plus(";${task.project.environment.pythonPath}") ?: task.project.environment.pythonPath

val pythonRunConfiguration = factory.createTemplateConfiguration(context.environment.project) as PythonRunConfiguration
pythonRunConfiguration.apply {
Expand All @@ -28,7 +30,7 @@ class PythonScriptCommandLineStateProvider : PaddleTaskRunProfileStateProvider<R
sdkHome = module.pythonSdk?.homePath
isModuleMode = task.isModuleMode
workingDirectory = context.moduleDir.absolutePath
setEnvs(mapOf("PYTHONPATH" to task.project.environment.pythonPath))
setEnvs(env)
setAddContentRoots(false)
setAddSourceRoots(false)
}
Expand Down

0 comments on commit cb0c110

Please sign in to comment.