Skip to content

Commit e89f86b

Browse files
naschemestefanseefeld
authored andcommitted
Update Linux CI scripts, more Python versions.
Update scripts to use actions/setup-python to install different Python versions. Add run-faber.sh and get-py-env.py scripts. Add test-ubuntu-py-ver.yml CI script to test with different Python versions.
1 parent 5013564 commit e89f86b

File tree

4 files changed

+194
-33
lines changed

4 files changed

+194
-33
lines changed

.github/get-py-env.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Determine info about the Python install and write shell code to stdout, to
4+
# set env variables. This will set the variables PY_LDFLAGS, PY_CFLAGS and
5+
# PY_INC_PATH.
6+
#
7+
# The python3-config tool is used as the source of this info. In theory we
8+
# could use sysconfig as well but the setup-python action from github appears
9+
# to patch python3-config but not patch the sysconfig info.
10+
#
11+
# Usage:
12+
# eval $(python3 get-py-env.py)
13+
14+
import os
15+
import re
16+
import subprocess
17+
18+
19+
def get_output(cmd):
20+
rv = subprocess.run(
21+
cmd,
22+
capture_output=True, # Capture stdout and stderr
23+
text=True, # Decode output as text (UTF-8)
24+
check=True, # Raise an error if the command fails
25+
)
26+
return rv.stdout
27+
28+
29+
def extract_flags(cmd, prefix):
30+
flags = []
31+
for part in get_output(cmd).split():
32+
part = part.strip()
33+
if part.startswith(prefix):
34+
flags.append(part)
35+
return ' '.join(flags)
36+
37+
38+
def find_python_h():
39+
"""Find the include path that has Python.h contained inside.
40+
We could use INCLUDEPY from sysconfig but github patches
41+
python3-config but not the sysconfig info (after moving the
42+
install).
43+
"""
44+
c_flags = extract_flags(['python3-config', '--cflags'], '-I')
45+
for part in c_flags.split():
46+
m = re.search(r'-I(\S+)', part)
47+
if not m:
48+
continue
49+
inc_path = m.group(1)
50+
if os.path.exists(os.path.join(inc_path, 'Python.h')):
51+
return inc_path
52+
raise SystemExit('cannot find Python.h')
53+
54+
55+
def main():
56+
ld_flags = extract_flags(['python3-config', '--ldflags'], '-L')
57+
c_flags = extract_flags(['python3-config', '--cflags'], '-I')
58+
include_path = find_python_h()
59+
print(f'PY_LDFLAGS="{ld_flags}"')
60+
print(f'PY_CFLAGS="{c_flags}"')
61+
print(f'PY_INC_PATH="{include_path}"')
62+
63+
64+
if __name__ == '__main__':
65+
main()

.github/run-faber.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
echo "cxx version: $CXX $($CXX --version)"
6+
echo "cxx std: $CXX_STD"
7+
echo "python3 path: $(which python3)"
8+
echo "python3 version: $(python3 --version)"
9+
10+
if ! which faber > /dev/null; then
11+
echo "Installing faber..."
12+
python3 -m pip install --upgrade pip
13+
python3 -m pip install -U faber
14+
fi
15+
echo "faber version: $(faber -v)"
16+
17+
# find and set PY_LDFLAGS and PY_INC_PATH
18+
eval $(python3 .github/get-py-env.py)
19+
20+
echo "PY_INC_PATH=$PY_INC_PATH"
21+
echo "PY_LDFLAGS=$PY_LDFLAGS"
22+
23+
case $(python3-config --abiflags) in
24+
*t*)
25+
# When running with free-threaded, we always want to disable the GIL
26+
# even for extensions without the mod_gil_not_used() flag
27+
export PYTHON_GIL=0
28+
;;
29+
esac
30+
31+
# this could be set by LD_LIBRARY_PATH but faber overrides it
32+
prefix=$(python3-config --prefix)
33+
echo "${prefix}/lib" > /etc/ld.so.conf.d/boost-ci.conf && ldconfig
34+
35+
sed -e "s/\$PYTHON/python3/g" .ci/faber > $HOME/.faber
36+
37+
faber \
38+
--with-boost-include=${BOOST_PY_DEPS} \
39+
--builddir=build \
40+
cxx.name="${CXX}" \
41+
cxxflags="-std=${CXX_STD}" \
42+
cppflags="-std=${CXX_STD}" \
43+
include="${PY_INC_PATH}" \
44+
ldflags="${PY_LDFLAGS}" \
45+
-j`nproc` \
46+
"$@"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Test Ubuntu, Python 2.x
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python: [python]
16+
cxx: [g++]
17+
std: [c++11]
18+
include:
19+
# Add the appropriate docker image for each compiler.
20+
# The images from teeks99/boost-python-test already have boost::python
21+
# pre-reqs installed, see:
22+
# https://github.com/teeks99/boost-python-test-docker
23+
- cxx: g++
24+
docker-img: teeks99/boost-python-test:gcc-15_1.89.0
25+
26+
container:
27+
image: ${{ matrix.docker-img }}
28+
29+
steps:
30+
- uses: actions/checkout@v5
31+
32+
- name: setup prerequisites
33+
run: |
34+
# Warning: this is not necessarily the same Python version as the one configured above !
35+
python3 -m pip install -U faber --break-system-packages
36+
- name: build
37+
run: |
38+
${{ matrix.python }} --version
39+
${{ matrix.cxx }} --version
40+
faber -v
41+
sed -e "s/\$PYTHON/${{ matrix.python }}/g" .ci/faber > ~/.faber
42+
faber \
43+
--with-boost-include=${BOOST_PY_DEPS} \
44+
--builddir=build \
45+
cxx.name=${{ matrix.cxx }} \
46+
cxxflags=-std=${{ matrix.std }} \
47+
cppflags=-std=${{ matrix.std }} \
48+
-j`nproc`
49+
- name: test
50+
run: |
51+
faber \
52+
--with-boost-include=${BOOST_PY_DEPS} \
53+
--builddir=build \
54+
cxx.name=${{ matrix.cxx }} \
55+
cxxflags=-std=${{ matrix.std }} \
56+
cppflags=-std=${{ matrix.std }} \
57+
-j`nproc` \
58+
test.report

.github/workflows/test-ubuntu.yml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# Test on Ubuntu with various compiler and language standard versions.
12
name: Test Ubuntu
23

3-
on: [push, pull_request]
4+
on:
5+
push:
6+
pull_request:
7+
workflow_dispatch:
48

59
jobs:
610
build:
@@ -9,49 +13,37 @@ jobs:
913
strategy:
1014
fail-fast: false
1115
matrix:
12-
python: [python, python3]
16+
python-version: ['3.14']
1317
cxx: [g++, clang++]
1418
std: [c++11, c++14, c++17]
1519
include:
16-
# Add the appropriate docker image for each compiler.
17-
# The images from teeks99/boost-python-test already have boost::python
18-
# pre-reqs installed, see:
19-
# https://github.com/teeks99/boost-python-test-docker
20-
- cxx: clang++
21-
docker-img: teeks99/boost-python-test:clang-21_1.89.0
22-
- cxx: g++
23-
docker-img: teeks99/boost-python-test:gcc-15_1.89.0
20+
# Also test with free-threaded build of Python
21+
- python-version: '3.14t'
22+
cxx: clang++
23+
std: c++17
2424

2525
container:
26-
image: ${{ matrix.docker-img }}
26+
# Add the appropriate docker image for the compiler.
27+
# The images from teeks99/boost-python-test already have boost::python
28+
# pre-reqs installed, see:
29+
# https://github.com/teeks99/boost-python-test-docker
30+
image: ${{ matrix.cxx == 'g++' &&
31+
'teeks99/boost-python-test:gcc-15_1.89.0' ||
32+
'teeks99/boost-python-test:clang-21_1.89.0' }}
2733

2834
steps:
2935
- uses: actions/checkout@v5
30-
36+
- name: setup python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: ${{ matrix.python-version }}
3140
- name: setup prerequisites
3241
run: |
33-
# Warning: this is not necessarily the same Python version as the one configured above !
34-
python3 -m pip install -U faber --break-system-packages
42+
echo "CXX=${{ matrix.cxx }}" >> "$GITHUB_ENV"
43+
echo "CXX_STD=${{ matrix.std }}" >> "$GITHUB_ENV"
3544
- name: build
3645
run: |
37-
${{ matrix.python }} --version
38-
${{ matrix.cxx }} --version
39-
faber -v
40-
sed -e "s/\$PYTHON/${{ matrix.python }}/g" .ci/faber > ~/.faber
41-
faber \
42-
--with-boost-include=${BOOST_PY_DEPS} \
43-
--builddir=build \
44-
cxx.name=${{ matrix.cxx }} \
45-
cxxflags=-std=${{ matrix.std }} \
46-
cppflags=-std=${{ matrix.std }} \
47-
-j`nproc`
46+
.github/run-faber.sh
4847
- name: test
4948
run: |
50-
faber \
51-
--with-boost-include=${BOOST_PY_DEPS} \
52-
--builddir=build \
53-
cxx.name=${{ matrix.cxx }} \
54-
cxxflags=-std=${{ matrix.std }} \
55-
cppflags=-std=${{ matrix.std }} \
56-
-j`nproc` \
57-
test.report
49+
.github/run-faber.sh test.report

0 commit comments

Comments
 (0)