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