Skip to content

Commit b7b0137

Browse files
committed
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 80731af commit b7b0137

File tree

3 files changed

+125
-24
lines changed

3 files changed

+125
-24
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+
"$@"

.github/workflows/test-ubuntu.yml

Lines changed: 14 additions & 24 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,7 +13,7 @@ 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:
@@ -27,31 +31,17 @@ jobs:
2731

2832
steps:
2933
- uses: actions/checkout@v5
30-
34+
- name: setup python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: ${{ matrix.python-version }}
3138
- name: setup prerequisites
3239
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
40+
echo "CXX=${{ matrix.cxx }}" >> "$GITHUB_ENV"
41+
echo "CXX_STD=${{ matrix.std }}" >> "$GITHUB_ENV"
3542
- name: build
3643
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`
44+
.github/run-faber.sh
4845
- name: test
4946
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
47+
.github/run-faber.sh test.report

0 commit comments

Comments
 (0)