Skip to content

Gradle: python code format/check #1986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build-logic/src/main/kotlin/polaris-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ checkstyle {
// Ensure Checkstyle runs after jandex to avoid task dependency issues
tasks.withType<Checkstyle>().configureEach { tasks.findByName("jandex")?.let { mustRunAfter(it) } }

tasks.checkstyleMain {
// Add the dependency on the root project's ruffCheck task
dependsOn(":ruffCheck")
}

tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
Expand Down Expand Up @@ -88,6 +93,7 @@ tasks.register("format").configure {
group = "verification"
description = "Runs all code formatting tasks"
dependsOn("spotlessApply")
dependsOn(":ruffFormat")
}

tasks.named<Test>("test").configure { jvmArgs("-Duser.language=en") }
Expand Down
22 changes: 22 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ plugins {
alias(libs.plugins.jetbrains.changelog)
// workaround for https://github.com/kordamp/jandex-gradle-plugin/issues/25
alias(libs.plugins.jandex) apply false
alias(libs.plugins.use.python)
}

val projectName = rootProject.file("ide-name.txt").readText().trim()
Expand Down Expand Up @@ -238,3 +239,24 @@ changelog {
)
version.set(provider { project.version.toString() })
}

python {
installVirtualenv = true
pip("ruff:${libs.versions.ruff.get()}")
}

tasks.register<Exec>("ruffFormat") {
description = "Run ruff format for python code"

workingDir = project.rootDir
commandLine("/bin/bash", "-c", "${project.rootDir.resolve(".gradle/python/bin/ruff").absolutePath} format client/python")
dependsOn("pipInstall")
}

tasks.register<Exec>("ruffCheck") {
description = "Run ruff check for python code"

workingDir = project.rootDir
commandLine("/bin/bash", "-c", "${project.rootDir.resolve(".gradle/python/bin/ruff").absolutePath} check --fix --exit-non-zero-on-fix client/python")
dependsOn("pipInstall")
}
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ scala212 = "2.12.19"
spark35 = "3.5.6"
slf4j = "2.0.17"
swagger = "1.6.16"
ruff = "0.12.1"

[bundles]

Expand Down Expand Up @@ -102,4 +103,5 @@ jandex = { id = "org.kordamp.gradle.jandex", version = "2.1.0" }
openapi-generator = { id = "org.openapi.generator", version = "7.12.0" }
quarkus = { id = "io.quarkus", version.ref = "quarkus" }
rat = { id = "org.nosphere.apache.rat", version = "0.8.1" }
jetbrains-changelog = { id = "org.jetbrains.changelog", version = "2.2.1"}
jetbrains-changelog = { id = "org.jetbrains.changelog", version = "2.2.1"}
use-python = { id = "ru.vyarus.use-python", version = "4.1.0" }
Loading