1
1
package com.uriyyo.evaluate_async_code
2
2
3
3
import com.intellij.execution.configurations.ParamsGroup
4
+ import com.intellij.openapi.application.PathManager
4
5
import com.intellij.openapi.projectRoots.Sdk
5
- import com.jetbrains.python.PythonHelper
6
6
import com.jetbrains.python.psi.LanguageLevel
7
7
import java.io.File
8
+ import java.nio.file.Paths
8
9
9
10
const val PYDEVD_ASYNC_DEBUG = " _pydevd_async_debug.py"
11
+ const val PLUGIN_NAME = " evaluate-async-code"
10
12
11
13
fun <T > (() -> T ).memoize(): (() -> T ) {
12
14
var result: T ? = null
@@ -16,15 +18,15 @@ fun <T> (() -> T).memoize(): (() -> T) {
16
18
}
17
19
}
18
20
19
- fun pydevRoot (): String = File (PythonHelper .CONSOLE .asParamString()).parent
20
-
21
21
val asyncPyDevScript: () -> File = {
22
- var script = File (pydevRoot (), PYDEVD_ASYNC_DEBUG )
22
+ var script = Paths .get( PathManager .getPluginsPath (), PLUGIN_NAME , PYDEVD_ASYNC_DEBUG ).toFile( )
23
23
24
- if (! script.canWrite())
24
+ try {
25
+ script.createNewFile()
26
+ } catch (e: Exception ) {
25
27
script = createTempFile(suffix = " .py" )
28
+ }
26
29
27
- script.createNewFile()
28
30
script.setReadable(true , false )
29
31
script.setWritable(true , false )
30
32
script.writeText(PYDEVD_ASYNC_MAIN_PLUGIN )
@@ -425,7 +427,7 @@ __async_exec_func_result__ = asyncio.get_event_loop().run_until_complete(__async
425
427
426
428
__patcher__()
427
429
del __patcher__
428
- """
430
+ """ .trimStart()
429
431
430
432
val PYDEVD_ASYNC_MAIN_PLUGIN = """
431
433
$PLUGIN
@@ -434,4 +436,4 @@ import sys
434
436
from runpy import run_path
435
437
436
438
run_path(sys.argv.pop(1), {}, "__main__")
437
- """
439
+ """ .trimStart()
0 commit comments