1+ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+ plugins {
4+ kotlin(" jvm" ) version " 1.8.22"
5+ }
6+
7+ tasks.test {
8+ useJUnitPlatform()
9+ }
10+
11+ repositories {
12+ mavenCentral()
13+ }
14+
15+ tasks {
16+ withType<JavaCompile > {
17+ sourceCompatibility = JavaVersion .VERSION_1_8 .toString()
18+ targetCompatibility = JavaVersion .VERSION_1_8 .toString()
19+ options.encoding = " UTF-8"
20+ options.compilerArgs = options.compilerArgs + " -Xlint:all" + " -Werror"
21+ }
22+ withType<KotlinCompile > {
23+ kotlinOptions {
24+ jvmTarget = JavaVersion .VERSION_1_8 .toString()
25+ freeCompilerArgs = freeCompilerArgs + " -Xallow-result-return-type" + " -Xsam-conversions=class"
26+ allWarningsAsErrors = true
27+ }
28+ }
29+ }
30+
31+ val kotlinLoggingVersion = " 1.8.3"
32+ val moshiVersion = " 1.15.1"
33+
34+ dependencies {
35+ implementation(" com.squareup.moshi:moshi:$moshiVersion " )
36+ implementation(" com.squareup.moshi:moshi-kotlin:$moshiVersion " )
37+ implementation(" com.squareup.moshi:moshi-adapters:$moshiVersion " )
38+ implementation(group = " io.github.microutils" , name = " kotlin-logging" , version = kotlinLoggingVersion)
39+
40+ testImplementation(kotlin(" test-junit5" ))
41+ }
42+
43+ val utbotMypyRunnerVersion = File (project.projectDir, " src/main/resources/utbot_mypy_runner_version" ).readText()
44+ // these two properties --- from GRADLE_USER_HOME/gradle.properties
45+ val pypiToken: String? by project
46+ val pythonInterpreter: String? by project
47+ val utbotMypyRunnerPath = File (project.projectDir, " src/main/python/utbot_mypy_runner" )
48+ val localMypyPath = File (utbotMypyRunnerPath, " dist" )
49+
50+ tasks.register(" cleanDist" ) {
51+ group = " python"
52+ delete(localMypyPath.canonicalPath)
53+ }
54+
55+ val installPoetry =
56+ if (pythonInterpreter != null ) {
57+ tasks.register<Exec >(" installPoetry" ) {
58+ group = " python"
59+ workingDir = utbotMypyRunnerPath
60+ commandLine(pythonInterpreter, " -m" , " pip" , " install" , " poetry" )
61+ }
62+ } else {
63+ null
64+ }
65+
66+ val setMypyRunnerVersion =
67+ if (pythonInterpreter != null ) {
68+ tasks.register<Exec >(" setVersion" ) {
69+ dependsOn(installPoetry!! )
70+ group = " python"
71+ workingDir = utbotMypyRunnerPath
72+ commandLine(pythonInterpreter, " -m" , " poetry" , " version" , utbotMypyRunnerVersion)
73+ }
74+ } else {
75+ null
76+ }
77+
78+ val buildMypyRunner =
79+ if (pythonInterpreter != null ) {
80+ tasks.register<Exec >(" buildUtbotMypyRunner" ) {
81+ dependsOn(setMypyRunnerVersion!! )
82+ group = " python"
83+ workingDir = utbotMypyRunnerPath
84+ commandLine(pythonInterpreter, " -m" , " poetry" , " build" )
85+ }
86+ } else {
87+ null
88+ }
89+
90+ if (pythonInterpreter != null && pypiToken != null ) {
91+ tasks.register<Exec >(" publishUtbotMypyRunner" ) {
92+ dependsOn(buildMypyRunner!! )
93+ group = " python"
94+ workingDir = utbotMypyRunnerPath
95+ commandLine(
96+ pythonInterpreter,
97+ " -m" ,
98+ " poetry" ,
99+ " publish" ,
100+ " -u" ,
101+ " __token__" ,
102+ " -p" ,
103+ pypiToken
104+ )
105+ }
106+ }
107+
108+ val uninstallMypyRunner =
109+ if (pythonInterpreter != null ) {
110+ tasks.register<Exec >(" uninstallMypyRunner" ) {
111+ group = " python"
112+ commandLine(
113+ pythonInterpreter,
114+ " -m" ,
115+ " pip" ,
116+ " uninstall" ,
117+ " utbot_mypy_runner"
118+ )
119+ commandLine(
120+ pythonInterpreter,
121+ " -m" ,
122+ " pip" ,
123+ " cache" ,
124+ " purge"
125+ )
126+ }
127+ } else {
128+ null
129+ }
130+
131+ val installMypyRunner =
132+ if (pythonInterpreter != null ) {
133+ tasks.register<Exec >(" installUtbotMypyRunner" ) {
134+ dependsOn(buildMypyRunner!! )
135+ group = " python"
136+ environment(" PIP_FIND_LINKS" to localMypyPath.canonicalPath)
137+ commandLine(
138+ pythonInterpreter,
139+ " -m" ,
140+ " pip" ,
141+ " install" ,
142+ " utbot_mypy_runner==$utbotMypyRunnerVersion "
143+ )
144+ }
145+ } else {
146+ null
147+ }
148+
149+ val samplesDir = File (project.projectDir, " src/test/resources/samples" )
150+ val buildDir = File (project.buildDir, " samples_builds" )
151+ val jsonDir = File (project.projectDir, " src/test/resources" )
152+
153+ fun getParamsForSample (sampleName : String ): List <String > =
154+ listOf (
155+ sampleName,
156+ File (samplesDir, " $sampleName .py" ).canonicalPath,
157+ sampleName,
158+ buildDir.canonicalPath,
159+ File (jsonDir, " $sampleName .json" ).canonicalPath
160+ )
161+
162+ val samplesInfo = listOf (
163+ getParamsForSample(" annotation_tests" ),
164+ getParamsForSample(" boruvka" ),
165+ getParamsForSample(" import_test" ),
166+ getParamsForSample(" subtypes" ),
167+ )
168+
169+ if (pythonInterpreter != null ) {
170+ val subtasks = samplesInfo.map { params ->
171+ tasks.register<JavaExec >(" regenerateJsonForTests_${params.first()} " ) {
172+ dependsOn(installMypyRunner!! )
173+ group = " python_subtasks"
174+ classpath = sourceSets.test.get().runtimeClasspath
175+ args = listOf (pythonInterpreter) + params.drop(1 )
176+ mainClass.set(" org.utbot.python.newtyping.samples.GenerateMypyInfoBuildKt" )
177+ }
178+ }
179+
180+ tasks.register(" regenerateJsonForTests" ) {
181+ subtasks.forEach { dependsOn(it) }
182+ group = " python"
183+ }
184+ }
0 commit comments