forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
165 lines (142 loc) · 5.74 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins { id 'org.apache.beam.module' }
applyPythonNature()
/*************************************************************************************************/
// Basic build and Python environment setup/cleanup
def buildPython = tasks.register("buildPython") {
dependsOn setupVirtualenv
doLast {
logger.info('Building Python Dependencies')
exec {
executable 'sh'
// args '-c', ". ${envdir}/bin/activate && python setup.py build --build-base ${buildDir}"
args '-c', ". ${envdir}/bin/activate && pip install -e ."
}
}
}
build.dependsOn tasks.named("buildPython")
// Create a Python source distribution tarball.
def tarball = "apache-beam.tar.gz"
def sdist = tasks.register("sdist") {
description "Create a Python source distribution tarball"
dependsOn setupVirtualenv
doLast {
// Build artifact
exec {
executable 'sh'
args '-c', ". ${envdir}/bin/activate && pip install -U build && python -m build --sdist --outdir=${buildDir}"
}
def collection = fileTree(buildDir){ include "**/*${project.sdk_version}*.tar.gz" exclude 'srcs/**'}
// we need a fixed name for the artifact
copy { from collection.singleFile; into buildDir; rename { tarball } }
logger.info('Create distribution tar file {} in {}', tarball, buildDir)
}
inputs.files(pythonSdkDeps)
.withPropertyName('pythonSdkDeps')
.withPathSensitivity(PathSensitivity.RELATIVE)
outputs.file "${buildDir}/${tarball}"
}
artifacts {
distTarBall file: file("${buildDir}/${tarball}"), builtBy: sdist
}
// Create Python wheels for given platform and Python version
// build identifiers for cibuildwheel
def platform_identifiers_map = [
linux: 'manylinux_*64*', // e.g. manylinux_x86_64, manylinux_aarch64
macos:'macosx_*64*', // e.g. macosx_x86_64, macosx_arm64
windows: 'win_*64*', // e.g. win_amd64, win_arm64
]
platform_identifiers_map.each { platform, idsuffix ->
def archs = 'auto'
// note: A fix for arm64 platform in gradle environment. For some reason the
// task fails with "Invalid archs option {<Architecture.arm64: 'arm64'>}."
// even though os.arch is 'aarch64'
// Running cibuildwheel command directly in shell it succeeded, however
if (platform == 'linux' && 'aarch64'.equalsIgnoreCase(System.getProperty("os.arch"))) {
archs = 'aarch64'
}
getVersionsAsList('python_versions').each { it ->
def pyversion = it.replace('.', '')
project.tasks.register("bdistPy${pyversion}${platform}") {
description "Build a Python wheel distribution for Py${pyversion} ${platform}"
dependsOn setupVirtualenv
// need sdist task to generate protos
dependsOn ':sdks:python:sdist'
// generated installable Python SDK package
doLast {
exec {
environment CIBW_BUILD: "cp${pyversion}-${idsuffix}"
environment CIBW_ENVIRONMENT: "SETUPTOOLS_USE_DISTUTILS=stdlib"
// note: sync cibuildwheel version with GitHub Action
// .github/workflow/build_wheel.yml:build_wheels "Install cibuildwheel" step
executable 'sh'
args '-c', ". ${envdir}/bin/activate && " +
"pip install cibuildwheel==2.9.0 && " +
"cibuildwheel --print-build-identifiers --platform ${platform} --archs ${archs} && " +
"cibuildwheel --output-dir ${buildDir} --platform ${platform} --archs ${archs}"
}
}
}
}
}
/*************************************************************************************************/
// Non-testing builds and analysis tasks
// Snapshot of dependency requirements defined in setup.py.
// Results will be stored in files under Gradle build directory.
def depSnapshot = tasks.register("depSnapshot") {
dependsOn installGcpTest
doLast {
def outputDir = file(buildDir)
if (!outputDir.exists()) {
outputDir.mkdirs()
}
def requirementsFile = "${outputDir}/requirements.txt"
logger.info('Snapshoting full dependencies requirements with versions info to build/requirements.txt.')
exec {
// Remove useless item "pkg-resources" from file which is introduced by a bug in Ubuntu.
executable 'sh'
args '-c', ". ${envdir}/bin/activate && pip freeze --local --all | grep -v \"pkg-resources\" > ${requirementsFile}"
}
}
}
tasks.register("buildSnapshot") {
dependsOn sdist
dependsOn depSnapshot
}
tasks.register("startPortableRunner") {
dependsOn buildPython
doLast {
def jobPort = project.findProperty("jobPort") ?: 8099
exec {
executable 'sh'
args '-c', ". ${envdir}/bin/activate && python -m apache_beam.runners.portability.local_job_service_main --job_port ${jobPort}"
}
}
}
// Run this task to validate the python environment setup for contributors
tasks.register("wordCount") {
description "Run the Python word count example"
dependsOn installGcpTest
doLast {
exec {
executable 'sh'
args '-c', ". ${envdir}/bin/activate && python -m apache_beam.examples.wordcount --runner DirectRunner --output /tmp/output.txt"
}
}
}