[skip ci] add possibility to install python packages in venv (important e.g. for remote installation)

This commit is contained in:
az 2023-05-23 09:56:31 +02:00
parent 5bd1432465
commit 72e5519cef

View file

@ -7,36 +7,49 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta
import java.io.File import java.io.File
fun Prov.provisionPython() = task { fun Prov.provisionPython(venvHome: String? = "~/.venv/meissa") = task {
installPython3() installPython3()
configureVenv() if (venvHome != null) { configureVenv(venvHome) }
installPybuilder() installPybuilder(venvHome)
installRestClient() installRestClient(venvHome)
installJupyterlab() installJupyterlab(venvHome)
} }
fun Prov.installPython3(): ProvResult = task { fun Prov.installPython3(): ProvResult = task {
aptInstall("python3-venv python3-pip") aptInstall("python3-venv python3-pip")
} }
fun Prov.configureVenv(): ProvResult = task { fun Prov.configureVenv(venvHome: String): ProvResult = task {
val venvHome = "~/.venv/meissa" cmd("python3 -m venv $venvHome")
cmd("python3 -m venv " + venvHome) createSymlink(File("$venvHome/bin/activate"), File("~/.bashrc.d/venv.sh"))
cmd("source " + venvHome + "/bin/activate") pipInstall("pip --upgrade", venvHome)
createSymlink(File(venvHome + "/bin/activate"), File("~/.bashrc.d/venv.sh"))
cmd("pip3 install pip --upgrade")
} }
fun Prov.installPybuilder(): ProvResult = task { fun Prov.installPybuilder(venvHome: String? = null): ProvResult = task {
cmd("pip3 install pybuilder ddadevops pypandoc mockito coverage unittest-xml-reporting deprecation" + pipInstall("pybuilder ddadevops pypandoc mockito coverage unittest-xml-reporting deprecation" +
" python_terraform dda_python_terraform boto3 pyyaml ") " python_terraform dda_python_terraform boto3 pyyaml ",
cmd("pip3 install --upgrade ddadevops") venvHome
)
pipInstall("--upgrade ddadevops", venvHome)
} }
fun Prov.installRestClient(): ProvResult = task { fun Prov.installRestClient(venvHome: String? = null): ProvResult = task {
cmd("pip3 install requests") pipInstall("requests", venvHome)
} }
fun Prov.installJupyterlab(): ProvResult = task { fun Prov.installJupyterlab(venvHome: String? = null): ProvResult = task {
cmd("pip3 install jupyterlab pandas matplotlib") pipInstall("jupyterlab pandas matplotlib", venvHome)
}
private fun Prov.pipInstall(pkg: String, venvHome: String? = null) {
cmd(activateVenvCommandPrefix(venvHome) + "pip3 install $pkg")
}
private fun activateVenvCommandPrefix(venvHome: String?): String {
return if (venvHome == null) {
""
} else {
"source $venvHome/bin/activate && "
}
} }