Skip to content

Commit df76239

Browse files
committed
Split up image provider execution
1 parent 5144f3f commit df76239

6 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/main/kotlin/com/github/srwi/pixellens/imageProviders/ImageProvider.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ abstract class ImageProvider {
4545

4646
private fun prepareData(frameAccessor: PyFrameAccessor, expression: String) {
4747
val functionDef = getDataPreparationFunction(FUNCTION_NAME)
48-
val statement = wrapDataPreparationCommand(functionDef, expression)
48+
Python.executeStatement(frameAccessor, functionDef)
49+
50+
val statement = wrapDataPreparationCommand(expression)
4951
Python.executeStatement(frameAccessor, statement)
5052
}
5153

52-
private fun wrapDataPreparationCommand(functionDef: String, variableName: String): String {
53-
val tryBlock = """
54+
private fun wrapDataPreparationCommand(variableName: String): String {
55+
return """
5456
try:
5557
$PAYLOAD_VARIABLE_NAME = $FUNCTION_NAME($variableName)
5658
finally:
5759
del $FUNCTION_NAME
58-
"""
59-
return functionDef.trimIndent() + "\n" + tryBlock.trimIndent()
60+
""".trimIndent()
6061
}
6162

6263
private fun cleanUpData(frameAccessor: PyFrameAccessor) {

src/main/kotlin/com/github/srwi/pixellens/imageProviders/JaxImageProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class JaxImageProvider : ImageProvider() {
1919
'dtype': str(variable.dtype)
2020
}
2121
return json.dumps(payload)
22-
"""
22+
""".trimIndent()
2323
}
2424

2525
override fun typeSupported(value: PyDebugValue): Boolean {

src/main/kotlin/com/github/srwi/pixellens/imageProviders/NumpyImageProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NumpyImageProvider : ImageProvider() {
1919
'dtype': str(variable.dtype)
2020
}
2121
return json.dumps(payload)
22-
"""
22+
""".trimIndent()
2323
}
2424

2525
override fun typeSupported(value: PyDebugValue): Boolean {

src/main/kotlin/com/github/srwi/pixellens/imageProviders/PillowImageProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PillowImageProvider : ImageProvider() {
1717
'dtype': variable.mode
1818
}
1919
return json.dumps(payload)
20-
"""
20+
""".trimIndent()
2121
}
2222

2323
override fun shapeSupported(value: PyDebugValue): Boolean {

src/main/kotlin/com/github/srwi/pixellens/imageProviders/PytorchImageProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PytorchImageProvider : ImageProvider() {
2020
'dtype': str(variable.dtype)[6:] # dtype starts with "torch."
2121
}
2222
return json.dumps(payload)
23-
"""
23+
""".trimIndent()
2424
}
2525

2626
override fun typeSupported(value: PyDebugValue): Boolean {

src/main/kotlin/com/github/srwi/pixellens/imageProviders/TensorflowImageProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TensorflowImageProvider : ImageProvider() {
1919
'dtype': str(img_array.dtype)
2020
}
2121
return json.dumps(payload)
22-
"""
22+
""".trimIndent()
2323
}
2424

2525
override fun typeSupported(value: PyDebugValue): Boolean {

0 commit comments

Comments
 (0)