@@ -57,31 +57,31 @@ pythonPlugin {
5757
5858tasks. register(' installPythonBuildTools' , VenvTask ) {
5959 group = ' build setup'
60- description = ' Installs Python packages needed to build the wheel.'
60+ description = ' Installs Python packages needed to build and test the wheel.'
6161
6262 venvExec = ' pip'
63- args = [' install' , ' --upgrade' , ' pip' , ' build' ]
64- }
65-
66- tasks. register(' buildPythonWheel' , VenvTask ) {
67- group = " distribution"
68- description = " Builds a Python .whl file using the Gradle-managed Python environment."
69-
70- dependsOn bundlePython
71- dependsOn installPythonBuildTools
63+ args = [' install' , ' --upgrade' , ' pip' , ' build' , ' pytest' ]
7264
73- workingDir = file(" ${ buildDir} /install/regi-python" )
74- venvExec = " python"
75- args = [" -m" , " build" , " --wheel" ]
65+ outputs. file(layout. buildDirectory. file(" python-build-tools/install.marker" ))
7666
7767 doLast {
78- println " Python Wheel built in: ${ workingDir} /dist"
68+ def markerFile = layout. buildDirectory. file(" python-build-tools/install.marker" ). get(). asFile
69+ markerFile. parentFile. mkdirs()
70+ markerFile. text = " pip build pytest installed\n "
7971 }
8072}
8173
8274tasks. register(' bundlePython' , Sync ) {
8375 description = ' Bundles Python scripts and creates the java_lib directory'
84- into " ${ buildDir} /install/regi-python/"
76+
77+ dependsOn jar
78+
79+ into layout. buildDirectory. dir(" install/regi-python" )
80+
81+ inputs. dir(" src/main/python" )
82+ inputs. file(jar. archiveFile)
83+ inputs. files(configurations. runtimeClasspath)
84+ inputs. property(" version" , project. version. toString())
8585
8686 from(' src/main/python' ) {
8787 include ' pyproject.toml'
@@ -99,34 +99,70 @@ tasks.register('bundlePython', Sync) {
9999 }
100100}
101101
102- tasks. register(' testPythonWheel' ) {
102+ tasks. register(' buildPythonWheel' , VenvTask ) {
103+ group = " distribution"
104+ description = " Builds a Python .whl file using the Gradle-managed Python environment."
105+
106+ dependsOn bundlePython
107+ dependsOn installPythonBuildTools
108+
109+ workingDir = layout. buildDirectory. dir(" install/regi-python" ). get(). asFile
110+ venvExec = " python"
111+ args = [" -m" , " build" , " --wheel" ]
112+
113+ inputs. files(fileTree(layout. buildDirectory. dir(" install/regi-python" )) {
114+ exclude " dist/**"
115+ exclude " build/**"
116+ exclude " *.egg-info/**"
117+ })
118+ inputs. property(" version" , project. version. toString())
119+ outputs. dir(layout. buildDirectory. dir(" install/regi-python/dist" ))
120+
121+ doFirst {
122+ delete layout. buildDirectory. dir(" install/regi-python/dist" )
123+ }
124+
125+ doLast {
126+ println " Python Wheel built in: ${ workingDir} /dist"
127+ }
128+ }
129+
130+ tasks. register(' installPythonWheelForSmokeTest' , VenvTask ) {
103131 group = ' verification'
104- description = ' Creates a venv, installs the wheel, and runs a test script.'
132+ description = ' Installs the built Python wheel into the Gradle-managed Python environment.'
133+
105134 dependsOn buildPythonWheel
106135
136+ venvExec = ' pip'
137+
138+ inputs. files(fileTree(dir : " ${ buildDir} /install/regi-python/dist" , include : ' *.whl' ))
139+ outputs. file(layout. buildDirectory. file(" test-python-wheel/install.marker" ))
140+
141+ doFirst {
142+ def wheelFile = fileTree(dir : " ${ buildDir} /install/regi-python/dist" , include : ' *.whl' ). singleFile
143+ args = [' install' , ' --force-reinstall' , wheelFile. absolutePath]
144+ }
145+
107146 doLast {
108- def venvName = " test_venv"
109- def wheelDir = " ${ projectDir} /build/install/regi-headless/dist"
110- def testScript = " src\\ test\\ resources\\ usace\\ rowcps\\ headless\\ examples\\ GateFlowCalc2_Jpype.py"
111-
112- // 1. Create VENV if it doesn't exist
113- exec {
114- commandLine ' cmd' , ' /c' , " python -m venv ${ venvName} "
115- }
116-
117- // 2. Install Wheel and Run Script
118- // We chain these using '&&' so they run in the same shell session where the venv is active
119- exec {
120- workingDir projectDir
121- def wheelFile = fileTree(dir : wheelDir, include : ' *.whl' ). singleFile. absolutePath
122- def venvActivate = file(" ${ venvName} /Scripts/activate.bat" ). absolutePath
123- environment ' CDA_URL' , project. findProperty(' CDA_URL' ) ?: " "
124- environment ' API_KEY' , project. findProperty(' API_KEY' ) ?: " "
125- environment ' OFFICE_ID' , project. findProperty(' OFFICE_ID' ) ?: " "
126- environment ' JAVA_HOME' , System . getProperty(' java.home' )
127- commandLine ' cmd' , ' /c' , " \" ${ venvActivate} \" && pip install --force-reinstall \" ${ wheelFile} \" && python -u ${ testScript} "
128- standardOutput = System . out
129- errorOutput = System . err
130- }
147+ def wheelFile = fileTree(dir : " ${ buildDir} /install/regi-python/dist" , include : ' *.whl' ). singleFile
148+ def markerFile = layout. buildDirectory. file(" test-python-wheel/install.marker" ). get(). asFile
149+ markerFile. parentFile. mkdirs()
150+ markerFile. text = " ${ wheelFile.name} \n ${ wheelFile.length()} bytes\n "
131151 }
132152}
153+ tasks. register(' testPythonWheel' , VenvTask ) {
154+ group = ' verification'
155+ description = ' Runs pytest against the installed Python wheel.'
156+
157+ dependsOn installPythonWheelForSmokeTest
158+
159+ venvExec = ' python'
160+ args = [' -m' , ' pytest' , ' src/test/python' ]
161+
162+ inputs. files(fileTree(dir : ' src/test/python' , include : ' **/*.py' ))
163+ outputs. upToDateWhen { false }
164+ }
165+
166+ check {
167+ dependsOn testPythonWheel
168+ }
0 commit comments