Created
April 29, 2020 21:09
-
-
Save marcellustavares/32abf31390ebf07213e7320be5979a16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.jetbrains.python.envs.PythonEnvsPlugin | |
import com.liferay.gradle.util.FileUtil | |
import org.apache.tools.ant.taskdefs.condition.Os | |
buildscript { | |
dependencies { | |
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.defaults", version: "latest.release" | |
classpath group: "gradle.plugin.com.jetbrains.python", name: "gradle-python-envs", version: "0.0.30" | |
} | |
repositories { | |
maven { | |
url "https://repository-cdn.liferay.com/nexus/content/groups/public" | |
} | |
} | |
} | |
configure(subprojects.findAll { FileUtil.exists(it, "src/main/python")}) { | |
apply plugin: PythonEnvsPlugin | |
task configureVirtualEnv() | |
task formatSourcePython() | |
task packagePython() | |
def pythonSource = "src/main/python" | |
envs { | |
bootstrapDirectory = new File(projectDir, '.bootstrap') | |
envsDirectory = new File(buildDir, '.envs') | |
conda "Miniconda3", "Miniconda3-py38_4.8.2", "64" | |
condaenv project.name, "3.8", "Miniconda3" | |
//doLast { | |
//println "Installing yapf" | |
//def pythonEnvDir = "$bootstrapDirectory/Miniconda3" | |
//exec { | |
// commandLine _executablePath(pythonEnvDir, "pip"), "install", "yapf" | |
//} | |
//} | |
} | |
task installCondaDependencies() { | |
//dependsOn build_condas | |
doLast { | |
println "Install Conda Deps" | |
def bootstrapDirectory = new File(projectDir, '.bootstrap') | |
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
copy { | |
from file("$bootstrapDirectory/Miniconda3/Library/bin/libcrypto-1_1-x64.dll"), file("$bootstrapDirectory/Miniconda3/Library/bin/libssl-1_1-x64.dll") | |
into file("$bootstrapDirectory/Miniconda3/DLLs") | |
} | |
} | |
} | |
} | |
task installCondaEnvDependencies() { | |
println "Install Conda Env Deps" | |
//if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
// copy { | |
// from file("$project.envs.envsDirectory/$project.name/Library/bin/libcrypto-1_1-x64.dll"), file("$bootstrapDirectory/Miniconda3/Library/bin/libssl-1_1-x64.dll") | |
// into file("$project.envs.envsDirectory/$project.name/DLLs") | |
// } | |
//} | |
//println "Installing env dependencies" | |
//def pythonEnvDir = "$project.envs.envsDirectory/.envs/$project.name" | |
//exec { | |
// commandLine _executablePath(pythonEnvDir, "pip"), "install", "-r", "$projectDir/$pythonSource/requirements.txt" | |
//} | |
} | |
formatSourcePython { | |
def pythonEnvDir = "$project.envs.bootstrapDirectory/Miniconda3" | |
doLast { | |
exec { | |
commandLine _executablePath(pythonEnvDir, "python"), "-m", "yapf", "-i", "--recursive", pythonSource | |
} | |
} | |
} | |
packagePython { | |
def buildLibs = new File("$buildDir/libs") | |
def pythonEnvDir = "$buildDir/.envs/$project.name" | |
def pythonTempDir = "$buildDir/python-temp" | |
doLast { | |
copy { | |
from pythonSource | |
into pythonTempDir | |
exclude "requirements-package.txt" | |
} | |
if (!buildLibs.exists()) { | |
buildLibs.mkdirs() | |
} | |
exec { | |
commandLine _executablePath(pythonEnvDir, "pip"), "install", "-r", "$projectDir/$pythonSource/requirements-package.txt", "--target", pythonTempDir | |
} | |
exec { | |
commandLine _executablePath(pythonEnvDir, "python"), "-m", "zipapp", pythonTempDir, "-o", "$buildDir/libs/${project.name}.py" | |
} | |
delete pythonTempDir | |
} | |
} | |
project.afterEvaluate { | |
//build_condas.finalizedBy configureCondaEnvironment | |
installCondaDependencies { | |
dependsOn build_condas | |
} | |
assemble { | |
dependsOn packagePython | |
} | |
//build_conda_envs { | |
// dependsOn configureCondaEnvironment | |
//} | |
//build_envs { | |
// dependsOn configureVirtualEnv | |
//} | |
formatSource { | |
dependsOn build_envs | |
} | |
packagePython { | |
dependsOn build_envs | |
} | |
} | |
} | |
private String _executablePath(String pythonEnvDir, String executable) { | |
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
return "$pythonEnvDir/Scripts/$executable" | |
} | |
else { | |
return "$pythonEnvDir/bin/$executable" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment