135 lines
4.1 KiB
Groovy
135 lines
4.1 KiB
Groovy
import ru.vyarus.gradle.plugin.python.task.PythonTask
|
|
|
|
plugins {
|
|
id 'base'
|
|
id 'ru.vyarus.use-python' version '2.3.0'
|
|
}
|
|
|
|
def generateCodeGeneratorImage = tasks.register('generateCodeGeneratorImage', Exec) {
|
|
commandLine 'bin/build_code_generator_image.sh'
|
|
}
|
|
def generateComponentManifestClassFiles = tasks.register('generateComponentManifestClassFiles', Exec) {
|
|
environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath
|
|
commandLine 'bin/generate-component-manifest-files.sh'
|
|
}
|
|
generateComponentManifestClassFiles.configure {
|
|
dependsOn generateCodeGeneratorImage
|
|
}
|
|
tasks.named('assemble').configure {
|
|
dependsOn generateComponentManifestClassFiles
|
|
}
|
|
|
|
tasks.register('validateSourceYamlManifest', Exec) {
|
|
environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath
|
|
commandLine 'bin/validate-yaml-schema.sh'
|
|
}
|
|
|
|
tasks.register('runLowCodeConnectorUnitTests', Exec) {
|
|
environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath
|
|
commandLine 'bin/low-code-unit-tests.sh'
|
|
}
|
|
|
|
def venvDirectoryName = '.venv'
|
|
|
|
// Add a task that allows cleaning up venvs to every python project
|
|
def cleanPythonVenv = tasks.register('cleanPythonVenv', Exec) {
|
|
commandLine 'rm'
|
|
args '-rf', "${projectDir.absolutePath}/${venvDirectoryName}"
|
|
}
|
|
|
|
tasks.named('clean').configure {
|
|
dependsOn cleanPythonVenv
|
|
}
|
|
|
|
// Configure gradle python plugin.
|
|
python {
|
|
envPath = venvDirectoryName
|
|
minPythonVersion '3.10'
|
|
|
|
// Amazon Linux support.
|
|
// The airbyte-ci tool runs gradle tasks in AL2023-based containers.
|
|
// In AL2023, `python3` is necessarily v3.9, and later pythons need to be installed and named explicitly.
|
|
// See https://github.com/amazonlinux/amazon-linux-2023/issues/459 for details.
|
|
try {
|
|
if ("python3.11 --version".execute().waitFor() == 0) {
|
|
// python3.11 definitely exists at this point, use it instead of 'python3'.
|
|
pythonBinary "python3.11"
|
|
}
|
|
} catch (IOException _) {
|
|
// Swallow exception if python3.11 is not installed.
|
|
}
|
|
// Pyenv support.
|
|
try {
|
|
def pyenvRoot = "pyenv root".execute()
|
|
def pyenvLatest = "pyenv latest ${minPythonVersion}".execute()
|
|
// Pyenv definitely exists at this point: use 'python' instead of 'python3' in all cases.
|
|
pythonBinary "python"
|
|
if (pyenvRoot.waitFor() == 0 && pyenvLatest.waitFor() == 0) {
|
|
pythonPath "${pyenvRoot.text.trim()}/versions/${pyenvLatest.text.trim()}/bin"
|
|
}
|
|
} catch (IOException _) {
|
|
// Swallow exception if pyenv is not installed.
|
|
}
|
|
|
|
scope 'VIRTUALENV'
|
|
installVirtualenv = true
|
|
pip 'pip:23.2.1'
|
|
pip 'mccabe:0.6.1'
|
|
// https://github.com/csachs/pyproject-flake8/issues/13
|
|
pip 'flake8:4.0.1'
|
|
// flake8 doesn't support pyproject.toml files
|
|
// and thus there is the wrapper "pyproject-flake8" for this
|
|
pip 'pyproject-flake8:0.0.1a2'
|
|
pip 'pytest:6.2.5'
|
|
pip 'coverage[toml]:6.3.1'
|
|
}
|
|
|
|
def installLocalReqs = tasks.register('installLocalReqs', PythonTask) {
|
|
module = "pip"
|
|
command = "install .[dev,tests]"
|
|
inputs.file('setup.py')
|
|
outputs.file('build/installedlocalreqs.txt')
|
|
}
|
|
|
|
def flakeCheck = tasks.register('flakeCheck', PythonTask) {
|
|
module = "pflake8"
|
|
command = "--config pyproject.toml ./"
|
|
}
|
|
|
|
def installReqs = tasks.register('installReqs', PythonTask) {
|
|
module = "pip"
|
|
command = "install .[main]"
|
|
inputs.file('setup.py')
|
|
outputs.file('build/installedreqs.txt')
|
|
}
|
|
installReqs.configure {
|
|
dependsOn installLocalReqs
|
|
}
|
|
|
|
tasks.named('check').configure {
|
|
dependsOn installReqs
|
|
dependsOn flakeCheck
|
|
}
|
|
|
|
def installTestReqs = tasks.register('installTestReqs', PythonTask) {
|
|
module = "pip"
|
|
command = "install .[tests]"
|
|
inputs.file('setup.py')
|
|
outputs.file('build/installedtestreqs.txt')
|
|
}
|
|
installTestReqs.configure {
|
|
dependsOn installReqs
|
|
}
|
|
|
|
def testTask = tasks.register('testPython', PythonTask) {
|
|
module = "coverage"
|
|
command = "run --data-file=unit_tests/.coverage.testPython --rcfile=pyproject.toml -m pytest -s unit_tests -c pytest.ini"
|
|
}
|
|
testTask.configure {
|
|
dependsOn installTestReqs
|
|
}
|
|
|
|
tasks.named('check').configure {
|
|
dependsOn testTask
|
|
}
|