Skip to content

Commit 52b2e15

Browse files
committed
🔧 Use plugin folder to store custom script
1 parent ad0b265 commit 52b2e15

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/com/uriyyo/evaluate_async_code/AsyncPyDebugUtils.kt

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.uriyyo.evaluate_async_code
22

33
import com.intellij.execution.configurations.ParamsGroup
4+
import com.intellij.openapi.application.PathManager
45
import com.intellij.openapi.projectRoots.Sdk
5-
import com.jetbrains.python.PythonHelper
66
import com.jetbrains.python.psi.LanguageLevel
77
import java.io.File
8+
import java.nio.file.Paths
89

910
const val PYDEVD_ASYNC_DEBUG = "_pydevd_async_debug.py"
11+
const val PLUGIN_NAME = "evaluate-async-code"
1012

1113
fun <T> (() -> T).memoize(): (() -> T) {
1214
var result: T? = null
@@ -16,15 +18,15 @@ fun <T> (() -> T).memoize(): (() -> T) {
1618
}
1719
}
1820

19-
fun pydevRoot(): String = File(PythonHelper.CONSOLE.asParamString()).parent
20-
2121
val asyncPyDevScript: () -> File = {
22-
var script = File(pydevRoot(), PYDEVD_ASYNC_DEBUG)
22+
var script = Paths.get(PathManager.getPluginsPath(), PLUGIN_NAME, PYDEVD_ASYNC_DEBUG).toFile()
2323

24-
if (!script.canWrite())
24+
try {
25+
script.createNewFile()
26+
} catch (e: Exception) {
2527
script = createTempFile(suffix = ".py")
28+
}
2629

27-
script.createNewFile()
2830
script.setReadable(true, false)
2931
script.setWritable(true, false)
3032
script.writeText(PYDEVD_ASYNC_MAIN_PLUGIN)
@@ -425,7 +427,7 @@ __async_exec_func_result__ = asyncio.get_event_loop().run_until_complete(__async
425427
426428
__patcher__()
427429
del __patcher__
428-
"""
430+
""".trimStart()
429431

430432
val PYDEVD_ASYNC_MAIN_PLUGIN = """
431433
$PLUGIN
@@ -434,4 +436,4 @@ import sys
434436
from runpy import run_path
435437
436438
run_path(sys.argv.pop(1), {}, "__main__")
437-
"""
439+
""".trimStart()

0 commit comments

Comments
 (0)