Simplify venv setup

This commit is contained in:
Jim Nicholson 2024-02-14 00:05:33 -08:00
parent ae067bf6c0
commit 78364a3016

View File

@ -26,6 +26,7 @@ void call(Map config = [:], Closure body) {
stage(runConfig.stepName) { stage(runConfig.stepName) {
printBanner(runConfig.stepName) printBanner(runConfig.stepName)
ansiColor('css') {
if (fileExists(runConfig.venvDir) && runConfig.recreateVenv) { if (fileExists(runConfig.venvDir) && runConfig.recreateVenv) {
echo 'Removing old venv...' echo 'Removing old venv...'
dir(runConfig.venvDir) { dir(runConfig.venvDir) {
@ -40,24 +41,25 @@ void call(Map config = [:], Closure body) {
} }
withEnv(venvEnv) { withEnv(venvEnv) {
List setupCmds = []
if (runConfig.updatePip) { if (runConfig.updatePip) {
updateCmd = "${venvPython.join('/')} -m pip install --upgrade pip" updateCmd = "${venvPython.join('/')} -m pip install --upgrade pip"
echo "Updating pip with (${updateCmd})" setupCmds.add(updateCmd)
echo "Environment is ${venvEnv}"
sh updateCmd
} }
if (runConfig.installPipTools) { if (runConfig.installPipTools) {
installCmd = "${venvPython.join('/')} -m pip install pip-tools" installCmd = "${venvPython.join('/')} -m pip install pip-tools"
echo "Installing pip-tools with (${installCmd})" setupCmds.add(installCmd)
sh installCmd
} }
if (fileExists(runConfig.requirementsFile)) { if (fileExists(runConfig.requirementsFile)) {
reqCmd = "pip-compile ${runConfig.requirementsFile}" reqCmd = "pip-compile ${runConfig.requirementsFile}"
echo "Collecting requirements with (${reqCmd})" setupCmds.add(reqCmd)
sh reqCmd }
if (!setupCmds.isEmpty()) {
sh setupCmds.join('\n')
} }
echo 'Executing closure...' echo 'Executing closure...'
body() body()
} }
} }
}
} }