Skip to content
Open
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ All Python dependencies are in the *environment.yml* file. The code is meant to

## Usage
### Usage withing the build process
To be added later.
The Gradle build will download Miniforge, create a local Python environment, and install the dependencies from the
environment.yml file. It will then run Pyinstaller on the Python sources to create an executable, zip it up,
and make it available to the rest of the Gradle ecosystem. To perform this action locally, run
`gradlew assemble`. The zip file will be located in the `build` directory.

### Post build implementation
After making any desired changes to the code, a new executable must be compiled and placed in the WAT build.
1. To create a conda environment, in a command prompt type: `conda env create -f environment.yml`
2. Activate the environment by running the line: `conda activate plotting-env`
3. Create an executable by running the line: `pyinstaller -y WAT_Report_Generator.py`
3. Create an executable by running the line: `pyinstaller -y src/main/python/WAT_Report_Generator.py`
4. In the WAT build *HEC-WAT/AutomatedReport* directory, delete any old files.
5. From the *dist/WAT_Report_Generator* directory, copy the *_internal* directory and *WAT_Report_Generator.exe* file and paste them into the WAT build */HEC-WAT/AutomatedReport* directory.
83 changes: 68 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,71 @@
plugins {
id "base"
id "maven-publish"
id "wtmp.deps-conventions"
id("com.pswidersk.python-plugin") version "3.1.10"
id "wtmp.versioning-conventions"
id "wtmp.publishing-conventions"
}

task zipPython(type: Zip) {
onlyIf { project.hasProperty("publishUSBRPython") && publishUSBRPython }
import com.pswidersk.gradle.python.VenvTask;

from 'dist/WAT_Report_Generator'
include '**/**'
allprojects {
group = 'usbr.wat.plugins'
version = versionConventions.getConventionVersion()
}

pythonPlugin {
pythonVersion = "3.11.0"
condaVersion = "25.3.1-0"
condaInstaller = "Miniforge3"
installDir = file(layout.buildDirectory.dir("python"))
}

def pythonSourceSet = objects.sourceDirectorySet("pythonSource", "pythonSource")
pythonSourceSet.srcDir('src/main/python')

tasks.register("installPackages", VenvTask) {
dependsOn("envSetup")

inputs.file("environment.yml")
outputs.upToDateWhen { !tasks.named("envSetup").get().didWork }

group = "build"

venvExec = "conda"
def envFile = layout.projectDirectory.file("environment.yml").asFile.getAbsolutePath()
args = ["env", "update", "--name", pythonPlugin.pythonEnvName$python_gradle_plugin.get(), "--file", envFile]

outputs.files([])
}

tasks.register("buildInstaller", VenvTask) {
dependsOn("installPackages")

def pyinstallerDir = layout.buildDirectory.dir("pyinstaller")
doFirst {
pyinstallerDir.get().getAsFile().mkdirs()
}

group = "build"

outputs.upToDateWhen { !tasks.named("installPackages").get().didWork }

inputs.files(pythonSourceSet.getSourceDirectories().files)

venvExec = "pyinstaller"
args = ["-y", "${pythonSourceSet.sourceDirectories.asPath}/WAT_Report_Generator.py"]
workingDir = pyinstallerDir

outputs.file(pyinstallerDir.get().dir("dist").dir("WAT_Report_Generator").file("WAT_Report_Generator.exe"))
}

tasks.register("zipPython", Zip) {
dependsOn("buildInstaller")

group = "build"

from tasks.named("buildInstaller")
include '**/**.exe'
archiveBaseName = 'usbr-actionpanel-python'
includeEmptyDirs = false
destinationDirectory = file("$projectDir/build")
Expand All @@ -16,23 +74,18 @@ task zipPython(type: Zip) {
fileCopyDetails.setRelativePath(fileCopyDetails.getRelativePath().prepend("HEC-WAT/AutomatedReport"))
}
}
if (project.hasProperty("publishUSBRPython") && publishUSBRPython) {
build.dependsOn(zipPython)
assemble.dependsOn(zipPython)

artifacts {
'default' zipPython
archives zipPython
}
assemble.dependsOn(tasks.named("zipPython"))

artifacts {
'default' tasks.named("zipPython")
}

publishing {
publications {
if (project.hasProperty("publishUSBRPython") && publishUSBRPython) {
maven(MavenPublication) {
artifactId = "usbr-actionpanel-python"
artifact source: zipPython, extension: 'zip'
artifact source: tasks.named("zipPython"), extension: 'zip'
}
}
}
}
12 changes: 12 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id 'groovy-gradle-plugin'
}

repositories {
gradlePluginPortal()
}

dependencies {
implementation("com.palantir.git-version:com.palantir.git-version.gradle.plugin:4.2.0")
implementation("org.ajoberstar.grgit:org.ajoberstar.grgit.gradle.plugin:4.1.1")
}
11 changes: 11 additions & 0 deletions buildSrc/src/main/groovy/wtmp.deps-conventions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'project-report'
}

repositories {
mavenCentral()
}

tasks.register("generateDependenciesReport", DependencyReportTask) { depReport ->
depReport.setConfiguration("runtimeClasspath")
}
4 changes: 4 additions & 0 deletions buildSrc/src/main/groovy/wtmp.publishing-conventions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id "maven-publish"
}

62 changes: 62 additions & 0 deletions buildSrc/src/main/groovy/wtmp.versioning-conventions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
plugins {
id "com.palantir.git-version"
id "org.ajoberstar.grgit"
}

tasks.register("showGit") {
doFirst {
def gitInfo = versionDetails()
println( "Used: " + getVersion() ) // The select version (the project.version field)
println( "Tag: " + gitInfo.lastTag) // actual tag or commit hash(short) if no tag
println( "Hash: " + gitInfo.gitHash) // short commit hash
println( "Branch: " + gitInfo.branchName) // branch name (null if tag checkout)
println( "TagBuild:" + gitInfo.isCleanTag) // true if repoi is in dettached head mode(e.g. git checkout <tag>)
}
}

def versionLabel(gitInfo) {
def branch = gitInfo.branchName // all branches are snapshots, only tags get released
if (branch == null && !"$System.env.CI_COMMIT_BRANCH".isEmpty()) {
branch = "$System.env.CI_COMMIT_BRANCH" // Gitlab CI checks out a commit, not a branch. Grab the branch name from the env vars it sets
}
def tag = gitInfo.lastTag
// tag is returned as is. Branch may need cleanup
return (branch == null || branch == "null" || branch.isEmpty()) ? tag : branch.replace("/","-") + "-SNAPSHOT"
}

/**
* When running on the Build System (eg TeamCity) will get BUILD_NUMBER
* Otherwise, gets the current commit (and status)
*/
String getBuildID() {
if(project.version.contains("-SNAPSHOT")) {
def buildNum = System.env.BUILD_NUMBER
if (!buildNum?.trim()) {
buildNum = "-${grgit.head().abbreviatedId}"
def clean = grgit.status().isClean()
if (!clean) {
buildNum += "+"
}
} else {
buildNum = "." + buildNum
}
return buildNum
} else {
// If dirty, return "+"
return grgit.status().isClean() ? "" : "+"
}
}

String getShortVersionName() {
String shortVersion = project.version
if(shortVersion.contains("-SNAPSHOT")) {
shortVersion = shortVersion.substring(0, shortVersion.indexOf("-SNAPSHOT"))
}
return shortVersion
}

String getConventionVersion() {
return versionLabel(versionDetails())
}

project.getExtensions().add("versionConventions", this)
5 changes: 5 additions & 0 deletions dwr-build-ext.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
includeBuild("$gradle.ext.externalLibDir") {
dependencySubstitution {
substitute(module("usbr.wat.plugins:usbr-actionpanel-python")).using(project(":"))
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading