Skip to content

Commit 7cbb3fb

Browse files
committed
Update Jenkins build to work with pyproject.toml
patch by Bret McGuire; reviewed by Bret McGuire and Brad Schoening reference: #1271
1 parent 3c13176 commit 7cbb3fb

4 files changed

Lines changed: 124 additions & 85 deletions

File tree

Jenkinsfile

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ slack = new Slack()
3434
DEFAULT_CASSANDRA = ['3.11', '4.0', '4.1', '5.0']
3535
DEFAULT_DSE = ['dse-5.1.35', 'dse-6.8.30', 'dse-6.9.0']
3636
DEFAULT_HCD = ['hcd-1.0.0']
37-
DEFAULT_RUNTIME = ['3.9.23', '3.10.18', '3.11.13', '3.12.11', '3.13.5']
37+
DEFAULT_RUNTIME = ['3.10.18', '3.11.13', '3.12.11', '3.13.5']
3838
DEFAULT_CYTHON = ["True", "False"]
3939
matrices = [
4040
"FULL": [
@@ -119,7 +119,7 @@ def getBuildContext() {
119119

120120
def buildAndTest(context) {
121121
initializeEnvironment()
122-
installDriverAndCompileExtensions()
122+
installDriver()
123123

124124
try {
125125
executeTests()
@@ -165,15 +165,18 @@ def getMatrixBuilds(buildContext) {
165165

166166
def initializeEnvironment() {
167167
sh label: 'Initialize the environment', script: '''#!/bin/bash -lex
168-
pyenv global ${PYTHON_VERSION}
169-
sudo apt-get install socat
170-
pip install --upgrade pip
171-
pip install -U setuptools
172168
173-
# install a version of pyyaml<6.0 compatible with ccm-3.1.5 as of Aug 2023
169+
# One of the integration tests relies on socat so let's install that here
170+
sudo apt-get install -y socat moreutils
171+
172+
pyenv shell ${PYTHON_VERSION}
173+
python -m venv jenkins-venv
174+
. ./jenkins-venv/bin/activate
175+
pip install --upgrade pip setuptools wheel
176+
177+
# Install a version of pyyaml<6.0 compatible with ccm-3.1.5 as of Aug 2023
174178
# this works around the python-3.10+ compatibility problem as described in DSP-23524
175-
pip install wheel
176-
pip install "Cython<3.0" "pyyaml<6.0" --no-build-isolation
179+
pip install "pyyaml<6.0" --no-build-isolation
177180
pip install ${HOME}/ccm
178181
'''
179182

@@ -182,35 +185,28 @@ def initializeEnvironment() {
182185
if (env.PYTHON_VERSION =~ /3\.12\.\d+/) {
183186
echo "Cannot install DSE dependencies for Python 3.12.x; installing Apache CassandraⓇ requirements only. See PYTHON-1368 for more detail."
184187
sh label: 'Install Apache CassandraⓇ requirements', script: '''#!/bin/bash -lex
188+
. ./jenkins-venv/bin/activate
185189
pip install -r test-requirements.txt
186190
'''
187191
}
188192
else {
189193
sh label: 'Install DataStax Enterprise requirements', script: '''#!/bin/bash -lex
194+
. ./jenkins-venv/bin/activate
190195
pip install -r test-datastax-requirements.txt
191196
'''
192197
}
193198
} else {
194199
sh label: 'Install Apache CassandraⓇ requirements', script: '''#!/bin/bash -lex
200+
. ./jenkins-venv/bin/activate
195201
pip install -r test-requirements.txt
196202
'''
197203

198204
sh label: 'Uninstall the geomet dependency since it is not required for Cassandra', script: '''#!/bin/bash -lex
205+
. ./jenkins-venv/bin/activate
199206
pip uninstall -y geomet
200207
'''
201208
}
202209

203-
sh label: 'Install unit test modules', script: '''#!/bin/bash -lex
204-
pip install --no-deps nose-ignore-docstring nose-exclude
205-
pip install service_identity
206-
'''
207-
208-
if (env.CYTHON_ENABLED == 'True') {
209-
sh label: 'Install cython modules', script: '''#!/bin/bash -lex
210-
pip install cython numpy
211-
'''
212-
}
213-
214210
sh label: 'Download Apache CassandraⓇ or DataStax Enterprise', script: '''#!/bin/bash -lex
215211
. ${CCM_ENVIRONMENT_SHELL} ${CASSANDRA_VERSION}
216212
'''
@@ -244,34 +240,55 @@ ENVIRONMENT_EOF
244240
}
245241

246242
sh label: 'Display Python and environment information', script: '''#!/bin/bash -le
243+
. ./jenkins-venv/bin/activate
244+
247245
# Load CCM environment variables
248246
set -o allexport
249247
. ${HOME}/environment.txt
250248
set +o allexport
251249
252250
python --version
253251
pip --version
254-
pip freeze
255252
printenv | sort
256253
'''
257254
}
258255

259-
def installDriverAndCompileExtensions() {
260-
if (env.CYTHON_ENABLED == 'True') {
261-
sh label: 'Install the driver and compile with C extensions with Cython', script: '''#!/bin/bash -lex
262-
python setup.py build_ext --inplace
263-
'''
264-
} else {
265-
sh label: 'Install the driver and compile with C extensions without Cython', script: '''#!/bin/bash -lex
266-
python setup.py build_ext --inplace --no-cython
267-
'''
268-
}
256+
def installDriver() {
257+
sh label: 'Install the driver and compile with C extensions with Cython', script: '''#!/bin/bash -lex
258+
# Update libev includes and libs to point to the right spot for this install
259+
pyenv shell ${PYTHON_VERSION}
260+
python -m venv libev-venv
261+
. ./libev-venv/bin/activate
262+
pip install toml
263+
python fix-jenkinsfile-libev.py ./pyproject.toml "/usr/include" "/usr/lib/x86_64-linux-gnu" | sponge ./pyproject.toml
264+
deactivate
265+
266+
ls /usr/include/ev.h
267+
ls /usr/lib/x86_64-linux-gnu/libev*
268+
269+
# Now that we've made relevant mods to our local pyproject.toml we're ready to build the driver
270+
. ./jenkins-venv/bin/activate
271+
272+
# Load CCM environment variables
273+
set -o allexport
274+
. ${HOME}/environment.txt
275+
set +o allexport
276+
277+
cat ./pyproject.toml
278+
pip install --verbose --editable .
279+
280+
# After install display a list of packages in the venv for auditing
281+
pip list
282+
'''
269283
}
270284

285+
271286
def executeStandardTests() {
272287

273288
try {
274289
sh label: 'Execute unit tests', script: '''#!/bin/bash -lex
290+
. ./jenkins-venv/bin/activate
291+
275292
# Load CCM environment variables
276293
set -o allexport
277294
. ${HOME}/environment.txt
@@ -289,6 +306,8 @@ def executeStandardTests() {
289306

290307
try {
291308
sh label: 'Execute Simulacron integration tests', script: '''#!/bin/bash -lex
309+
. ./jenkins-venv/bin/activate
310+
292311
# Load CCM environment variables
293312
set -o allexport
294313
. ${HOME}/environment.txt
@@ -314,6 +333,8 @@ def executeStandardTests() {
314333

315334
try {
316335
sh label: 'Execute CQL engine integration tests', script: '''#!/bin/bash -lex
336+
. ./jenkins-venv/bin/activate
337+
317338
# Load CCM environment variables
318339
set -o allexport
319340
. ${HOME}/environment.txt
@@ -330,6 +351,8 @@ def executeStandardTests() {
330351

331352
try {
332353
sh label: 'Execute Apache CassandraⓇ integration tests', script: '''#!/bin/bash -lex
354+
. ./jenkins-venv/bin/activate
355+
333356
# Load CCM environment variables
334357
set -o allexport
335358
. ${HOME}/environment.txt
@@ -351,6 +374,8 @@ def executeStandardTests() {
351374
else {
352375
try {
353376
sh label: 'Execute DataStax Enterprise integration tests', script: '''#!/bin/bash -lex
377+
. ./jenkins-venv/bin/activate
378+
354379
# Load CCM environment variable
355380
set -o allexport
356381
. ${HOME}/environment.txt
@@ -369,6 +394,8 @@ def executeStandardTests() {
369394

370395
try {
371396
sh label: 'Execute DataStax Astra integration tests', script: '''#!/bin/bash -lex
397+
. ./jenkins-venv/bin/activate
398+
372399
# Load CCM environment variable
373400
set -o allexport
374401
. ${HOME}/environment.txt
@@ -386,6 +413,8 @@ def executeStandardTests() {
386413
if (env.PROFILE == 'FULL') {
387414
try {
388415
sh label: 'Execute long running integration tests', script: '''#!/bin/bash -lex
416+
. ./jenkins-venv/bin/activate
417+
389418
# Load CCM environment variable
390419
set -o allexport
391420
. ${HOME}/environment.txt
@@ -404,6 +433,8 @@ def executeStandardTests() {
404433

405434
def executeDseSmokeTests() {
406435
sh label: 'Execute profile DataStax Enterprise smoke test integration tests', script: '''#!/bin/bash -lex
436+
. ./jenkins-venv/bin/activate
437+
407438
# Load CCM environment variable
408439
set -o allexport
409440
. ${HOME}/environment.txt
@@ -418,6 +449,8 @@ def executeDseSmokeTests() {
418449

419450
def executeEventLoopTests() {
420451
sh label: 'Execute profile event loop manager integration tests', script: '''#!/bin/bash -lex
452+
. ./jenkins-venv/bin/activate
453+
421454
# Load CCM environment variable
422455
set -o allexport
423456
. ${HOME}/environment.txt

fix-jenkinsfile-libev.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
import toml
3+
4+
pyproject = toml.load(sys.argv[1])
5+
base = pyproject["tool"]["cassandra-driver"]
6+
base["libev-includes"] = [sys.argv[2]]
7+
base["libev-libs"] = [sys.argv[3]]
8+
9+
print(toml.dumps(pyproject))

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ include = ['cassandra', 'cassandra.io', 'cassandra.cqlengine', 'cassandra.graph'
5151
build-murmur3-extension = true
5252
build-libev-extension = true
5353
build-cython-extensions = true
54-
libev-includes = []
55-
libev-libs = []
54+
libev-includes = ["/usr/include/libev", "/usr/local/include", "/opt/local/include", "/usr/include"]
55+
libev-libs = ["/usr/local/lib", "/opt/local/lib", "/usr/lib64"]
5656
build-concurrency = 0

setup.py

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
is_pypy = "PyPy" in sys.version
3131
is_supported_platform = sys.platform != "cli" and not sys.platform.startswith("java")
3232
is_supported_arch = sys.byteorder != "big"
33+
is_supported = is_supported_platform and is_supported_arch
3334

3435
# ========================== A few upfront checks ==========================
3536
platform_unsupported_msg = \
@@ -66,62 +67,58 @@
6667
pyproject_data = toml.load(f)
6768
driver_project_data = pyproject_data["tool"]["cassandra-driver"]
6869

69-
murmur3_ext = Extension('cassandra.cmurmur3', sources=['cassandra/cmurmur3.c'])
70-
71-
DEFAULT_LIBEV_INCLUDES = ['/usr/include/libev', '/usr/local/include', '/opt/local/include', '/usr/include']
72-
DEFAULT_LIBEV_LIBS = ['/usr/local/lib', '/opt/local/lib', '/usr/lib64']
73-
libev_includes = driver_project_data["libev-includes"] or DEFAULT_LIBEV_INCLUDES
74-
libev_libs = driver_project_data["libev-libs"] or DEFAULT_LIBEV_LIBS
75-
if is_macos:
76-
libev_includes.extend(['/opt/homebrew/include', os.path.expanduser('~/homebrew/include')])
77-
libev_libs.extend(['/opt/homebrew/lib'])
78-
libev_ext = Extension('cassandra.io.libevwrapper',
79-
sources=['cassandra/io/libevwrapper.c'],
80-
include_dirs=libev_includes,
81-
libraries=['ev'],
82-
library_dirs=libev_libs)
83-
84-
try_murmur3 = driver_project_data["build-murmur3-extension"] and is_supported_platform and is_supported_arch
85-
try_libev = driver_project_data["build-libev-extension"] and is_supported_platform and is_supported_arch
86-
try_cython = driver_project_data["build-cython-extensions"] and is_supported_platform and is_supported_arch and not is_pypy
70+
def key_or_false(k):
71+
return driver_project_data[k] if k in driver_project_data else False
72+
73+
try_murmur3 = key_or_false("build-murmur3-extension") and is_supported
74+
try_libev = key_or_false("build-libev-extension") and is_supported
75+
try_cython = key_or_false("build-cython-extensions") and is_supported and not is_pypy
8776

8877
build_concurrency = driver_project_data["build-concurrency"]
8978

90-
def build_extension_list():
91-
92-
rv = []
93-
94-
if try_murmur3:
95-
sys.stderr.write("Appending murmur extension %s\n" % murmur3_ext)
96-
rv.append(murmur3_ext)
97-
98-
if try_libev:
99-
sys.stderr.write("Appending libev extension %s\n" % libev_ext)
100-
rv.append(libev_ext)
101-
102-
if try_cython:
103-
sys.stderr.write("Trying Cython builds in order to append Cython extensions\n")
104-
try:
105-
from Cython.Build import cythonize
106-
cython_candidates = ['cluster', 'concurrent', 'connection', 'cqltypes', 'metadata',
107-
'pool', 'protocol', 'query', 'util']
108-
compile_args = [] if is_windows else ['-Wno-unused-function']
109-
rv.extend(cythonize(
110-
[Extension('cassandra.%s' % m, ['cassandra/%s.py' % m],
111-
extra_compile_args=compile_args)
112-
for m in cython_candidates],
113-
nthreads=build_concurrency,
114-
exclude_failures=True))
115-
116-
rv.extend(cythonize(Extension("*", ["cassandra/*.pyx"], extra_compile_args=compile_args),
117-
nthreads=build_concurrency))
118-
except Exception as exc:
119-
sys.stderr.write("Failed to cythonize one or more modules. These will not be compiled as extensions (optional).\n")
120-
sys.stderr.write("Cython error: %s\n" % exc)
121-
122-
return rv
79+
exts = []
80+
if try_murmur3:
81+
murmur3_ext = Extension('cassandra.cmurmur3', sources=['cassandra/cmurmur3.c'])
82+
sys.stderr.write("Appending murmur extension %s\n" % murmur3_ext)
83+
exts.append(murmur3_ext)
84+
85+
if try_libev:
86+
libev_includes = driver_project_data["libev-includes"]
87+
libev_libs = driver_project_data["libev-libs"]
88+
if is_macos:
89+
libev_includes.extend(['/opt/homebrew/include', os.path.expanduser('~/homebrew/include')])
90+
libev_libs.extend(['/opt/homebrew/lib'])
91+
libev_ext = Extension('cassandra.io.libevwrapper',
92+
sources=['cassandra/io/libevwrapper.c'],
93+
include_dirs=libev_includes,
94+
libraries=['ev'],
95+
library_dirs=libev_libs)
96+
sys.stderr.write("Appending libev extension %s\n" % libev_ext)
97+
exts.append(libev_ext)
98+
99+
if try_cython:
100+
sys.stderr.write("Trying Cython builds in order to append Cython extensions\n")
101+
try:
102+
from Cython.Build import cythonize
103+
cython_candidates = ['cluster', 'concurrent', 'connection', 'cqltypes', 'metadata',
104+
'pool', 'protocol', 'query', 'util']
105+
compile_args = [] if is_windows else ['-Wno-unused-function']
106+
exts.extend(cythonize(
107+
[Extension('cassandra.%s' % m, ['cassandra/%s.py' % m],
108+
extra_compile_args=compile_args)
109+
for m in cython_candidates],
110+
nthreads=build_concurrency,
111+
exclude_failures=True))
112+
113+
exts.extend(cythonize(
114+
Extension("*", ["cassandra/*.pyx"],
115+
extra_compile_args=compile_args),
116+
nthreads=build_concurrency))
117+
except Exception as exc:
118+
sys.stderr.write("Failed to cythonize one or more modules. These will not be compiled as extensions (optional).\n")
119+
sys.stderr.write("Cython error: %s\n" % exc)
123120

124121
# ========================== And finally setup() itself ==========================
125122
setup(
126-
ext_modules = build_extension_list()
123+
ext_modules = exts
127124
)

0 commit comments

Comments
 (0)