Skip to content

Commit dc088bc

Browse files
author
Marius Posta
authored
gradle: split off python cdk (#35306)
1 parent b741045 commit dc088bc

File tree

18 files changed

+551
-554
lines changed

18 files changed

+551
-554
lines changed

.github/workflows/publish-cdk-command-manually.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
repository: ${{ github.event.inputs.repo }}
7474
ref: ${{ github.event.inputs.gitref }}
7575
- name: Build CDK Package
76-
run: ./gradlew --no-daemon --no-build-cache :airbyte-cdk:python:build
76+
run: (cd airbyte-cdk/python; ./gradlew --no-daemon --no-build-cache :build)
7777
- name: Post failure to Slack channel dev-connectors-extensibility
7878
if: ${{ failure() }}
7979
uses: slackapi/[email protected]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
DOCKER_BUILD_ARCH="${DOCKER_BUILD_ARCH:-amd64}"
6+
# https://docs.docker.com/develop/develop-images/build_enhancements/
7+
export DOCKER_BUILDKIT=1
8+
9+
CODE_GENERATOR_DOCKERFILE="$(dirname $0)/../code-generator/Dockerfile"
10+
test -f $CODE_GENERATOR_DOCKERFILE
11+
docker build --build-arg DOCKER_BUILD_ARCH="$DOCKER_BUILD_ARCH" -t "airbyte/code-generator:dev" - < $CODE_GENERATOR_DOCKERFILE

airbyte-cdk/python/build.gradle

Lines changed: 115 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,134 @@
1+
import ru.vyarus.gradle.plugin.python.task.PythonTask
2+
13
plugins {
2-
id 'airbyte-python'
3-
id 'airbyte-docker-legacy'
4+
id 'base'
5+
id 'ru.vyarus.use-python' version '2.3.0'
46
}
57

8+
def generateCodeGeneratorImage = tasks.register('generateCodeGeneratorImage', Exec) {
9+
commandLine 'bin/build_code_generator_image.sh'
10+
}
611
def generateComponentManifestClassFiles = tasks.register('generateComponentManifestClassFiles', Exec) {
7-
environment 'ROOT_DIR', rootDir.absolutePath
12+
environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath
813
commandLine 'bin/generate-component-manifest-files.sh'
914
}
1015
generateComponentManifestClassFiles.configure {
11-
dependsOn project(':tools:code-generator').tasks.named('assemble')
16+
dependsOn generateCodeGeneratorImage
1217
}
1318
tasks.register('generate').configure {
1419
dependsOn generateComponentManifestClassFiles
1520
}
1621

1722
tasks.register('validateSourceYamlManifest', Exec) {
18-
environment 'ROOT_DIR', rootDir.absolutePath
23+
environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath
1924
commandLine 'bin/validate-yaml-schema.sh'
2025
}
2126

2227
tasks.register('runLowCodeConnectorUnitTests', Exec) {
23-
environment 'ROOT_DIR', rootDir.absolutePath
28+
environment 'ROOT_DIR', rootDir.parentFile.parentFile.absolutePath
2429
commandLine 'bin/low-code-unit-tests.sh'
2530
}
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+
}

airbyte-cdk/python/gradle.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# NOTE: some of these values are overwritten in CI!
2+
# NOTE: if you want to override this for your local machine, set overrides in ~/.gradle/gradle.properties
3+
4+
org.gradle.parallel=true
5+
org.gradle.caching=true
6+
7+
# Note, this might have issues on the normal Github runner.
8+
org.gradle.vfs.watch=true
9+
10+
# Tune # of cores Gradle uses.
11+
# org.gradle.workers.max=3
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)