Skip to content

Commit 1986248

Browse files
committed
enabled the compiler plugin completely for :samples
1 parent 315045c commit 1986248

File tree

12 files changed

+426
-437
lines changed

12 files changed

+426
-437
lines changed

samples/build.gradle.kts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ plugins {
2323
alias(kotlin.jvm)
2424
alias(korro)
2525
alias(ktlint)
26-
// Compiler plugin doesn't work properly for now: https://github.com/Kotlin/dataframe/issues/1432
2726
alias(dataframe.compiler.plugin)
28-
// using deprecated gradle plugin instead
29-
// alias(dataframe)
3027
// alias(kover)
3128
alias(ksp)
3229
}
@@ -37,7 +34,7 @@ repositories {
3734
mavenLocal() // for local development
3835
}
3936

40-
val dependentProjectPaths = with(projects) {
37+
val dependentProjects = with(projects) {
4138
listOf(
4239
core,
4340
dataframeArrow,
@@ -46,25 +43,34 @@ val dependentProjectPaths = with(projects) {
4643
dataframeCsv,
4744
dataframeJson,
4845
)
49-
}.map { it.path }
46+
}.map { project(it.path) }
5047

5148
tasks.compileKotlin {
52-
dependentProjectPaths.forEach {
53-
dependsOn("$it:jar")
49+
dependentProjects.forEach {
50+
dependsOn("${it.path}:jar")
5451
}
5552
}
5653

57-
val jarPaths = dependentProjectPaths.map {
58-
project(it).configurations
54+
val dependentProjectJarPaths = dependentProjects.map {
55+
it.configurations
5956
.getByName("instrumentedJars")
6057
.artifacts.single()
6158
.file.absolutePath
6259
.replace(File.separatorChar, '/')
6360
}
6461

6562
dependencies {
66-
// implementation(projects.dataframe) Must depend on jars for the compiler plugin to work!
67-
implementation(files(jarPaths))
63+
// implementation(projects.dataframe) // Must depend on jars for the compiler plugin to work!
64+
implementation(files(dependentProjectJarPaths))
65+
66+
// include api() dependencies from dependent projects, as they are not included in the jars
67+
dependentProjects.forEach {
68+
it.configurations.getByName("api").dependencies.forEach { dep ->
69+
if (dep is ExternalModuleDependency) {
70+
implementation("${dep.group}:${dep.name}:${dep.version ?: "+"}")
71+
}
72+
}
73+
}
6874

6975
testImplementation(libs.junit)
7076
testImplementation(libs.kotestAssertions) {

samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/DataFrameSampleHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.samples
22

33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
5+
import org.jetbrains.kotlinx.dataframe.samples.api.TestBase
56
import org.jetbrains.kotlinx.kandy.letsplot.samples.SampleHelper
67

78
abstract class DataFrameSampleHelper(sampleName: String, subFolder: String = "samples") :
@@ -10,7 +11,7 @@ abstract class DataFrameSampleHelper(sampleName: String, subFolder: String = "sa
1011
subFolder,
1112
"../docs/StardustDocs/images",
1213
"../docs/StardustDocs/resources",
13-
) {
14+
), TestBase {
1415

1516
fun DataColumn<*>.saveDfHtmlSample() {
1617
toDataFrame().saveDfHtmlSample()
Lines changed: 103 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,103 @@
1-
//@file:Suppress("UNUSED_VARIABLE", "unused", "UNCHECKED_CAST", "ktlint", "ClassName")
2-
//
3-
//package org.jetbrains.kotlinx.dataframe.samples.api
4-
//
5-
//import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
6-
//import org.jetbrains.kotlinx.dataframe.api.add
7-
//import org.jetbrains.kotlinx.dataframe.api.all
8-
//import org.jetbrains.kotlinx.dataframe.api.cast
9-
//import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
10-
//import org.jetbrains.kotlinx.dataframe.api.filter
11-
//import org.jetbrains.kotlinx.dataframe.api.generateCode
12-
//import org.jetbrains.kotlinx.dataframe.api.generateDataClasses
13-
//import org.jetbrains.kotlinx.dataframe.api.generateInterfaces
14-
//import org.jetbrains.kotlinx.dataframe.api.into
15-
//import org.jetbrains.kotlinx.dataframe.api.rename
16-
//import org.jetbrains.kotlinx.dataframe.api.sumOf
17-
//import org.jetbrains.kotlinx.dataframe.api.toList
18-
//import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper
19-
//import org.junit.Test
20-
//
21-
//class Generate : DataFrameSampleHelper("generate_docs", "api") {
22-
// private val ordersAlice = dataFrameOf(
23-
// "orderId" to listOf(101, 102),
24-
// "amount" to listOf(50.0, 75.5),
25-
// )
26-
//
27-
// private val ordersBob = dataFrameOf(
28-
// "orderId" to listOf(103, 104, 105),
29-
// "amount" to listOf(20.0, 30.0, 25.0),
30-
// )
31-
//
32-
// private val df = dataFrameOf(
33-
// "user" to listOf("Alice", "Bob"),
34-
// "orders" to listOf(ordersAlice, ordersBob),
35-
// )
36-
//
37-
// @DataSchema(isOpen = false)
38-
// interface _DataFrameType11 {
39-
// val amount: kotlin.Double
40-
// val orderId: kotlin.Int
41-
// }
42-
//
43-
// @DataSchema
44-
// interface _DataFrameType1 {
45-
// val orders: List<_DataFrameType11>
46-
// val user: kotlin.String
47-
// }
48-
//
49-
// @DataSchema
50-
// data class Customer1(val amount: Double, val orderId: Int)
51-
//
52-
// @DataSchema
53-
// data class Customer(val orders: List<Customer1>, val user: String)
54-
//
55-
// @Test
56-
// fun notebook_test_generate_docs_1() {
57-
// // SampleStart
58-
// df
59-
// // SampleEnd
60-
// .saveDfHtmlSample()
61-
// }
62-
//
63-
// @Test
64-
// fun notebook_test_generate_docs_2() {
65-
// // SampleStart
66-
// df.generateInterfaces()
67-
// // SampleEnd
68-
// }
69-
//
70-
// @Test
71-
// fun notebook_test_generate_docs_3() {
72-
// // SampleStart
73-
// df.filter { orders.all { orderId >= 102 } }
74-
// // SampleEnd
75-
// // .saveDfHtmlSample()
76-
// }
77-
//
78-
// @Test
79-
// fun notebook_test_generate_docs_4() {
80-
// // SampleStart
81-
// df.generateDataClasses("Customer")
82-
// // SampleEnd
83-
// }
84-
//
85-
// @Test
86-
// fun notebook_test_generate_docs_5() {
87-
// // SampleStart
88-
// val customers: List<Customer> = df.cast<Customer>().toList()
89-
// // SampleEnd
90-
// }
91-
//
92-
// @Test
93-
// fun notebook_test_generate_docs_6() {
94-
// // SampleStart
95-
// df.generateCode("Customer")
96-
// // SampleEnd
97-
// }
98-
//
99-
// @Test
100-
// fun notebook_test_generate_docs_7() {
101-
// // SampleStart
102-
// df.cast<Customer>()
103-
// .add("ordersTotal") { orders.sumOf { it.amount } }
104-
// .filter { user.startsWith("A") }
105-
// .rename { user }.into("customer")
106-
// // SampleEnd
107-
// // .saveDfHtmlSample()
108-
// }
109-
//}
1+
@file:Suppress("UNUSED_VARIABLE", "unused", "UNCHECKED_CAST", "ktlint", "ClassName")
2+
3+
package org.jetbrains.kotlinx.dataframe.samples.api
4+
5+
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
6+
import org.jetbrains.kotlinx.dataframe.api.add
7+
import org.jetbrains.kotlinx.dataframe.api.all
8+
import org.jetbrains.kotlinx.dataframe.api.cast
9+
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
10+
import org.jetbrains.kotlinx.dataframe.api.filter
11+
import org.jetbrains.kotlinx.dataframe.api.generateDataClasses
12+
import org.jetbrains.kotlinx.dataframe.api.generateInterfaces
13+
import org.jetbrains.kotlinx.dataframe.api.into
14+
import org.jetbrains.kotlinx.dataframe.api.rename
15+
import org.jetbrains.kotlinx.dataframe.api.sumOf
16+
import org.jetbrains.kotlinx.dataframe.api.toList
17+
import org.jetbrains.kotlinx.dataframe.samples.DataFrameSampleHelper
18+
import org.junit.Test
19+
20+
class Generate : DataFrameSampleHelper("generate_docs", "api") {
21+
22+
@DataSchema
23+
interface Orders {
24+
val orderId: Int
25+
val amount: Double
26+
}
27+
28+
private val ordersAlice = dataFrameOf(
29+
"orderId" to listOf(101, 102),
30+
"amount" to listOf(50.0, 75.5),
31+
).cast<Orders>()
32+
33+
private val ordersBob = dataFrameOf(
34+
"orderId" to listOf(103, 104, 105),
35+
"amount" to listOf(20.0, 30.0, 25.0),
36+
).cast<Orders>()
37+
38+
@DataSchema
39+
interface Customer {
40+
val user: String
41+
val orders: List<Orders>
42+
}
43+
44+
private val df = dataFrameOf(
45+
"user" to listOf("Alice", "Bob"),
46+
"orders" to listOf(ordersAlice, ordersBob),
47+
).cast<Customer>()
48+
49+
@Test
50+
fun notebook_test_generate_docs_1() {
51+
// SampleStart
52+
df
53+
// SampleEnd
54+
.saveDfHtmlSample()
55+
}
56+
57+
@Test
58+
fun notebook_test_generate_docs_2() {
59+
// SampleStart
60+
df.generateInterfaces()
61+
// SampleEnd
62+
}
63+
64+
@Test
65+
fun notebook_test_generate_docs_3() {
66+
// SampleStart
67+
df.filter { orders.all { orderId >= 102 } }
68+
// SampleEnd
69+
// .saveDfHtmlSample()
70+
}
71+
72+
@Test
73+
fun notebook_test_generate_docs_4() {
74+
// SampleStart
75+
df.generateDataClasses("Customer")
76+
// SampleEnd
77+
}
78+
79+
@Test
80+
fun notebook_test_generate_docs_5() {
81+
// SampleStart
82+
val customers: List<Customer> = df.toList()
83+
// SampleEnd
84+
}
85+
86+
@Test
87+
fun notebook_test_generate_docs_6() {
88+
// SampleStart
89+
df.generateInterfaces(markerName = "Customer")
90+
// SampleEnd
91+
}
92+
93+
@Test
94+
fun notebook_test_generate_docs_7() {
95+
// SampleStart
96+
df
97+
.add("ordersTotal") { orders.sumOf { it.amount } }
98+
.filter { user.startsWith("A") }
99+
.rename { user }.into("customer")
100+
// SampleEnd
101+
// .saveDfHtmlSample()
102+
}
103+
}

0 commit comments

Comments
 (0)