[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
fun Prov.provisionPython() = task {
fun Prov.provisionPython(venvHome: String? = "~/.venv/meissa") = task {
installPython3()
configureVenv()
installPybuilder()
installRestClient()
installJupyterlab()
if (venvHome != null) { configureVenv(venvHome) }
installPybuilder(venvHome)
installRestClient(venvHome)
installJupyterlab(venvHome)
}
fun Prov.installPython3(): ProvResult = task {
aptInstall("python3-venv python3-pip")
}
fun Prov.configureVenv(): ProvResult = task {
val venvHome = "~/.venv/meissa"
cmd("python3 -m venv " + venvHome)
cmd("source " + venvHome + "/bin/activate")
createSymlink(File(venvHome + "/bin/activate"), File("~/.bashrc.d/venv.sh"))
cmd("pip3 install pip --upgrade")
fun Prov.configureVenv(venvHome: String): ProvResult = task {
cmd("python3 -m venv $venvHome")
createSymlink(File("$venvHome/bin/activate"), File("~/.bashrc.d/venv.sh"))
pipInstall("pip --upgrade", venvHome)
}
fun Prov.installPybuilder(): ProvResult = task {
cmd("pip3 install pybuilder ddadevops pypandoc mockito coverage unittest-xml-reporting deprecation" +
" python_terraform dda_python_terraform boto3 pyyaml ")
cmd("pip3 install --upgrade ddadevops")
fun Prov.installPybuilder(venvHome: String? = null): ProvResult = task {
pipInstall("pybuilder ddadevops pypandoc mockito coverage unittest-xml-reporting deprecation" +
" python_terraform dda_python_terraform boto3 pyyaml ",
venvHome
)
pipInstall("--upgrade ddadevops", venvHome)
}
fun Prov.installRestClient(): ProvResult = task {
cmd("pip3 install requests")
fun Prov.installRestClient(venvHome: String? = null): ProvResult = task {
pipInstall("requests", venvHome)
}
fun Prov.installJupyterlab(): ProvResult = task {
cmd("pip3 install jupyterlab pandas matplotlib")
fun Prov.installJupyterlab(venvHome: String? = null): ProvResult = task {
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 && "
}
}