|
| 1 | +import ru.vyarus.gradle.plugin.python.task.PythonTask |
| 2 | + |
1 | 3 | plugins {
|
2 |
| - id 'airbyte-python' |
3 |
| - id 'airbyte-docker-legacy' |
| 4 | + id 'base' |
| 5 | + id 'ru.vyarus.use-python' version '2.3.0' |
4 | 6 | }
|
5 | 7 |
|
| 8 | +def generateCodeGeneratorImage = tasks.register('generateCodeGeneratorImage', Exec) { |
| 9 | + commandLine 'bin/build_code_generator_image.sh' |
| 10 | +} |
6 | 11 | def generateComponentManifestClassFiles = tasks.register('generateComponentManifestClassFiles', Exec) {
|
7 |
| - environment 'ROOT_DIR', rootDir.absolutePath |
| 12 | + environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath |
8 | 13 | commandLine 'bin/generate-component-manifest-files.sh'
|
9 | 14 | }
|
10 | 15 | generateComponentManifestClassFiles.configure {
|
11 |
| - dependsOn project(':tools:code-generator').tasks.named('assemble') |
| 16 | + dependsOn generateCodeGeneratorImage |
12 | 17 | }
|
13 | 18 | tasks.register('generate').configure {
|
14 | 19 | dependsOn generateComponentManifestClassFiles
|
15 | 20 | }
|
16 | 21 |
|
17 | 22 | tasks.register('validateSourceYamlManifest', Exec) {
|
18 |
| - environment 'ROOT_DIR', rootDir.absolutePath |
| 23 | + environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath |
19 | 24 | commandLine 'bin/validate-yaml-schema.sh'
|
20 | 25 | }
|
21 | 26 |
|
22 | 27 | tasks.register('runLowCodeConnectorUnitTests', Exec) {
|
23 |
| - environment 'ROOT_DIR', rootDir.absolutePath |
| 28 | + environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath |
24 | 29 | commandLine 'bin/low-code-unit-tests.sh'
|
25 | 30 | }
|
| 31 | + |
| 32 | +def venvDirectoryName = '.venv' |
| 33 | + |
| 34 | +// Add a task that allows cleaning up venvs to every python project |
| 35 | +def cleanPythonVenv = tasks.register('cleanPythonVenv', Exec) { |
| 36 | + commandLine 'rm' |
| 37 | + args '-rf', "${projectDir.absolutePath}/${venvDirectoryName}" |
| 38 | +} |
| 39 | + |
| 40 | +tasks.named('clean').configure { |
| 41 | + dependsOn cleanPythonVenv |
| 42 | +} |
| 43 | + |
| 44 | +// Configure gradle python plugin. |
| 45 | +python { |
| 46 | + envPath = venvDirectoryName |
| 47 | + minPythonVersion '3.10' |
| 48 | + |
| 49 | + // Amazon Linux support. |
| 50 | + // The airbyte-ci tool runs gradle tasks in AL2023-based containers. |
| 51 | + // In AL2023, `python3` is necessarily v3.9, and later pythons need to be installed and named explicitly. |
| 52 | + // See https://github.com/amazonlinux/amazon-linux-2023/issues/459 for details. |
| 53 | + try { |
| 54 | + if ("python3.11 --version".execute().waitFor() == 0) { |
| 55 | + // python3.11 definitely exists at this point, use it instead of 'python3'. |
| 56 | + pythonBinary "python3.11" |
| 57 | + } |
| 58 | + } catch (IOException _) { |
| 59 | + // Swallow exception if python3.11 is not installed. |
| 60 | + } |
| 61 | + // Pyenv support. |
| 62 | + try { |
| 63 | + def pyenvRoot = "pyenv root".execute() |
| 64 | + def pyenvLatest = "pyenv latest ${minPythonVersion}".execute() |
| 65 | + // Pyenv definitely exists at this point: use 'python' instead of 'python3' in all cases. |
| 66 | + pythonBinary "python" |
| 67 | + if (pyenvRoot.waitFor() == 0 && pyenvLatest.waitFor() == 0) { |
| 68 | + pythonPath "${pyenvRoot.text.trim()}/versions/${pyenvLatest.text.trim()}/bin" |
| 69 | + } |
| 70 | + } catch (IOException _) { |
| 71 | + // Swallow exception if pyenv is not installed. |
| 72 | + } |
| 73 | + |
| 74 | + scope 'VIRTUALENV' |
| 75 | + installVirtualenv = true |
| 76 | + pip 'pip:23.2.1' |
| 77 | + pip 'mccabe:0.6.1' |
| 78 | + // https://github.com/csachs/pyproject-flake8/issues/13 |
| 79 | + pip 'flake8:4.0.1' |
| 80 | + // flake8 doesn't support pyproject.toml files |
| 81 | + // and thus there is the wrapper "pyproject-flake8" for this |
| 82 | + pip 'pyproject-flake8:0.0.1a2' |
| 83 | + pip 'pytest:6.2.5' |
| 84 | + pip 'coverage[toml]:6.3.1' |
| 85 | +} |
| 86 | + |
| 87 | +def installLocalReqs = tasks.register('installLocalReqs', PythonTask) { |
| 88 | + module = "pip" |
| 89 | + command = "install .[dev,tests]" |
| 90 | + inputs.file('setup.py') |
| 91 | + outputs.file('build/installedlocalreqs.txt') |
| 92 | +} |
| 93 | + |
| 94 | +def flakeCheck = tasks.register('flakeCheck', PythonTask) { |
| 95 | + module = "pflake8" |
| 96 | + command = "--config pyproject.toml ./" |
| 97 | +} |
| 98 | + |
| 99 | +def installReqs = tasks.register('installReqs', PythonTask) { |
| 100 | + module = "pip" |
| 101 | + command = "install .[main]" |
| 102 | + inputs.file('setup.py') |
| 103 | + outputs.file('build/installedreqs.txt') |
| 104 | +} |
| 105 | +installReqs.configure { |
| 106 | + dependsOn installLocalReqs |
| 107 | +} |
| 108 | + |
| 109 | +tasks.named('check').configure { |
| 110 | + dependsOn installReqs |
| 111 | + dependsOn flakeCheck |
| 112 | +} |
| 113 | + |
| 114 | +def installTestReqs = tasks.register('installTestReqs', PythonTask) { |
| 115 | + module = "pip" |
| 116 | + command = "install .[tests]" |
| 117 | + inputs.file('setup.py') |
| 118 | + outputs.file('build/installedtestreqs.txt') |
| 119 | +} |
| 120 | +installTestReqs.configure { |
| 121 | + dependsOn installReqs |
| 122 | +} |
| 123 | + |
| 124 | +def testTask = tasks.register('testPython', PythonTask) { |
| 125 | + module = "coverage" |
| 126 | + command = "run --data-file=unit_tests/.coverage.testPython --rcfile=pyproject.toml -m pytest -s unit_tests -c pytest.ini" |
| 127 | +} |
| 128 | +testTask.configure { |
| 129 | + dependsOn installTestReqs |
| 130 | +} |
| 131 | + |
| 132 | +tasks.named('check').configure { |
| 133 | + dependsOn testTask |
| 134 | +} |
0 commit comments