Skip to content

Commit f23722b

Browse files
committed
Building 3.9+ OK. Try 3.8 then 3.7 then 3.6.
1 parent 745bcdb commit f23722b

File tree

8 files changed

+281
-22
lines changed

8 files changed

+281
-22
lines changed

HISTORY.rst

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
History
2+
##################
3+
4+
0.2.0 (2024-07-06)
5+
=====================
6+
7+
-
8+
9+
0.1.0 (2023-10-03)
10+
=====================
11+
12+
- First release.
13+
- Development Status :: 3 - Alpha

build_all.sh

+85-10
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,61 @@ set -o nounset # abort on unbound variable
1212
set -o pipefail # don't hide errors within pipes
1313

1414
# For current versions see https://devguide.python.org/versions/
15-
#PYTHON_VERSIONS=('3.9' '3.10' '3.11' '3.12')
16-
PYTHON_VERSIONS=('3.11')
15+
PYTHON_VERSIONS=('3.6' '3.7' '3.8' '3.9' '3.10' '3.11' '3.12' '3.13')
16+
#PYTHON_VERSIONS=('3.11' '3.12' '3.13')
17+
#PYTHON_VERSIONS=('3.7')
18+
#PYTHON_VERSIONS=('3.9' '3.10')
19+
#PYTHON_VERSIONS=('3.6' '3.7' '3.8' '3.9' '3.10')
20+
#PYTHON_VERSIONS=('3.8' '3.9' '3.10')
1721
# Used for venvs
1822
PYTHON_VENV_ROOT="${HOME}/pyenvs"
1923
PROJECT_NAME="PyExtPatt"
2024
#CPP_EXECUTABLE="PyExtPatt"
2125

26+
usage()
27+
{
28+
echo "usage: build_all.sh [-d] [-r] [-h, --help]"
29+
echo "options:"
30+
echo " -h, --help Print help and exit."
31+
echo " -d Build documentation (slow)."
32+
echo " -r Remove and rebuild all virtual environments."
33+
}
34+
35+
# If -h or --help print help.
36+
for arg in "$@"
37+
do
38+
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]
39+
then
40+
usage
41+
exit
42+
fi
43+
done
44+
45+
OPT_REMOVE_REBUILD_VENVS=false
46+
OPT_BUILD_DOCUMENTATION=false
47+
48+
if [[ "$#" -gt 0 ]]; then
49+
#while [ -n "$1" ]; do # while loop starts
50+
# case "$1" in
51+
# -r) OPT_REMOVE_REBUILD_VENVS=true ;; # Remove existing venvs and rebuild them.
52+
# -d) OPT_BUILD_DOCUMENTATION=true ;; # Build documentation.
53+
# --)
54+
# shift # The double dash which separates options from parameters
55+
# break
56+
# ;;
57+
# *) break;;
58+
# esac
59+
# shift
60+
#done
61+
for arg in "$@"
62+
do
63+
case "$arg" in
64+
-r) OPT_REMOVE_REBUILD_VENVS=true ;; # Remove existing venvs and rebuild them.
65+
-d) OPT_BUILD_DOCUMENTATION=true ;; # Build documentation.
66+
esac
67+
done
68+
fi
69+
2270
#printf "%-8s %8s %10s %10s %12s\n" "Ext" "Files" "Lines" "Words" "Bytes"
2371

2472
#build_cpp() {
@@ -55,6 +103,19 @@ create_virtual_environments() {
55103
echo "---> Creating virtual environment at: ${venv_path}"
56104
"python${version}" -m venv "${venv_path}"
57105
fi
106+
# https://stackoverflow.com/questions/42997258/virtualenv-activate-script-wont-run-in-bash-script-with-set-euo
107+
set +u
108+
source "${venv_path}/bin/activate"
109+
set -u
110+
echo "---> Python version:"
111+
python -VV
112+
echo "---> Installing everything via pip:"
113+
pip install -U pip setuptools wheel
114+
pip install -r requirements.txt
115+
# Needed for uploading to pypi
116+
pip install twine
117+
echo "---> Result of pip install:"
118+
pip list
58119
done
59120
}
60121

@@ -82,20 +143,22 @@ create_and_test_bdist_wheel() {
82143
# Control will enter here if directory doesn't exist.
83144
echo "---> Creating virtual environment at: ${venv_path}"
84145
"python${version}" -m venv "${venv_path}"
146+
else
147+
echo "---> EXISTING Virtual environment at: ${venv_path}"
85148
fi
86149
# https://stackoverflow.com/questions/42997258/virtualenv-activate-script-wont-run-in-bash-script-with-set-euo
87150
set +u
88151
source "${venv_path}/bin/activate"
89152
set -u
90153
echo "---> Python version:"
91154
python -VV
92-
echo "---> Installing everything via pip:"
93-
pip install -U pip setuptools wheel
94-
pip install -r requirements.txt
95-
# Needed for uploading to pypi
96-
pip install twine
97-
echo "---> Result of pip install:"
98-
pip list
155+
# echo "---> Installing everything via pip:"
156+
# pip install -U pip setuptools wheel
157+
# pip install -r requirements.txt
158+
# # Needed for uploading to pypi
159+
# pip install twine
160+
# echo "---> Result of pip install:"
161+
# pip list
99162
echo "---> Running python setup.py develop:"
100163
# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop
101164
python setup.py develop
@@ -106,6 +169,8 @@ create_and_test_bdist_wheel() {
106169
# pytest tests --runslow --benchmark-sort=name
107170
# pytest tests -v
108171
echo "---> Running setup for bdist_wheel:"
172+
# Need wheel otherwise bdist_wheel "error: invalid command 'bdist_wheel'"
173+
pip install wheel
109174
python setup.py bdist_wheel
110175
done
111176
}
@@ -140,8 +205,9 @@ report_all_versions_and_setups() {
140205
# Control will enter here if directory doesn't exist.
141206
echo "---> Creating virtual environment at: ${venv_path}"
142207
"python${version}" -m venv "${venv_path}"
208+
else
209+
echo "---> EXISTING Virtual environment at: ${venv_path}"
143210
fi
144-
echo "---> Virtual environment at: ${venv_path}"
145211
# https://stackoverflow.com/questions/42997258/virtualenv-activate-script-wont-run-in-bash-script-with-set-euo
146212
set +u
147213
source "${venv_path}/bin/activate"
@@ -159,6 +225,7 @@ show_results_of_dist() {
159225
echo "---> dist/:"
160226
ls -l "dist"
161227
echo "---> twine check dist/*:"
228+
pip install twine
162229
twine check dist/*
163230
# Test from Test PyPi
164231
# pip install -i https://test.pypi.org/simple/orderedstructs
@@ -176,18 +243,26 @@ show_results_of_dist() {
176243
echo "===> Removing build/ and dist/"
177244
#rm --recursive --force -- "build" "dist"
178245
rm -rf -- "build" "dist"
246+
247+
if [ $OPT_REMOVE_REBUILD_VENVS = true ]; then
179248
echo "===> Removing virtual environments"
180249
remove_virtual_environments
181250
echo "===> Creating virtual environments"
182251
create_virtual_environments
252+
fi
253+
183254
echo "===> Creating binary wheels"
184255
create_and_test_bdist_wheel
185256
echo "===> Creating source distribution"
186257
create_sdist
187258
echo "===> All versions and setups:"
188259
report_all_versions_and_setups
260+
261+
if [ $OPT_BUILD_DOCUMENTATION = true ]; then
189262
echo "===> Building documentation:"
190263
create_documentation
264+
fi
265+
191266
echo "===> dist/ result:"
192267
show_results_of_dist
193268
#deactivate_virtual_environment

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"""
88
import os
99

10-
from distutils.core import setup, Extension
1110
import os
11+
from setuptools import setup, Extension
1212
import sysconfig
1313

1414
DEBUG = True
@@ -35,8 +35,7 @@
3535

3636
PACKAGE_NAME = 'cPyExtPatt'
3737

38-
from distutils.core import setup, Extension
39-
38+
# For keywords see: https://setuptools.pypa.io/en/latest/references/keywords.html
4039
setup(
4140
name=PACKAGE_NAME,
4241
version='0.2.0',
@@ -46,6 +45,7 @@
4645
maintainer_email='[email protected]',
4746
description='Python C Extension Patterns.',
4847
long_description="""Examples of good and bad practice with Python C Extensions.""",
48+
long_description_content_type='text/plain',
4949
platforms=['Mac OSX', 'POSIX', ],
5050
classifiers=[
5151
'Development Status :: 3 - Alpha',

src/cpy/cObject.c

+46-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ static PyTypeObject ObjectWithAttributes_Type = {
9898
0, /*tp_itemsize*/
9999
/* methods */
100100
(destructor) ObjectWithAttributes_dealloc, /*tp_dealloc*/
101+
#if PY_MINOR_VERSION < 8
101102
0, /*tp_print*/
103+
#else
104+
0, /* Py_ssize_t tp_vectorcall_offset; */
105+
#endif
102106
(getattrfunc) 0, /*tp_getattr*/
103107
(setattrfunc) ObjectWithAttributes_setattr, /*tp_setattr*/
104108
0, /*tp_reserved*/
@@ -142,7 +146,18 @@ static PyTypeObject ObjectWithAttributes_Type = {
142146
NULL, /* tp_del */
143147
0, /* tp_version_tag */
144148
NULL, /* tp_finalize */
149+
#if PY_MINOR_VERSION > 7
145150
NULL, /* tp_vectorcall */
151+
#endif
152+
#if PY_MINOR_VERSION == 8
153+
0, /*tp_print*/
154+
#endif
155+
#if PY_MINOR_VERSION >= 12
156+
'\0', /* unsigned char tp_watched */
157+
#if PY_MINOR_VERSION >= 13
158+
0, /* uint16_t tp_versions_used */
159+
#endif
160+
#endif
146161
};
147162
/* --------------------------------------------------------------------- */
148163

@@ -224,7 +239,11 @@ static PyTypeObject Str_Type = {
224239
0, /*tp_itemsize*/
225240
/* methods */
226241
0, /*tp_dealloc*/
242+
#if PY_MINOR_VERSION < 8
227243
0, /*tp_print*/
244+
#else
245+
0, /* Py_ssize_t tp_vectorcall_offset; */
246+
#endif
228247
0, /*tp_getattr*/
229248
0, /*tp_setattr*/
230249
0, /*tp_reserved*/
@@ -267,7 +286,18 @@ static PyTypeObject Str_Type = {
267286
NULL, /* tp_del */
268287
0, /* tp_version_tag */
269288
NULL, /* tp_finalize */
289+
#if PY_MINOR_VERSION > 7
270290
NULL, /* tp_vectorcall */
291+
#endif
292+
#if PY_MINOR_VERSION == 8
293+
0, /*tp_print*/
294+
#endif
295+
#if PY_MINOR_VERSION >= 12
296+
'\0', /* unsigned char tp_watched */
297+
#if PY_MINOR_VERSION >= 13
298+
0, /* uint16_t tp_versions_used */
299+
#endif
300+
#endif
271301
};
272302

273303
/* ---------- */
@@ -286,7 +316,11 @@ static PyTypeObject Null_Type = {
286316
0, /*tp_basicsize*/
287317
0, /*tp_itemsize*/
288318
/* methods */
289-
0, /*tp_dealloc*/
319+
#if PY_MINOR_VERSION < 8
320+
0, /*tp_print*/
321+
#else
322+
0, /* Py_ssize_t tp_vectorcall_offset; */
323+
#endif
290324
0, /*tp_print*/
291325
0, /*tp_getattr*/
292326
0, /*tp_setattr*/
@@ -330,7 +364,18 @@ static PyTypeObject Null_Type = {
330364
NULL, /* tp_del */
331365
0, /* tp_version_tag */
332366
NULL, /* tp_finalize */
367+
#if PY_MINOR_VERSION > 7
333368
NULL, /* tp_vectorcall */
369+
#endif
370+
#if PY_MINOR_VERSION == 8
371+
0, /*tp_print*/
372+
#endif
373+
#if PY_MINOR_VERSION >= 12
374+
'\0', /* unsigned char tp_watched */
375+
#if PY_MINOR_VERSION >= 13
376+
0, /* uint16_t tp_versions_used */
377+
#endif
378+
#endif
334379
};
335380

336381

src/cpy/cPyRefs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static PyObject *make_tuple(PyObject *Py_UNUSED(module)) {
100100
PyObject *v;
101101

102102
r = PyTuple_New(3); /* New reference. */
103-
fprintf(stdout, "Ref count new: %zd\n", r->ob_refcnt);
103+
// fprintf(stdout, "Ref count new: %zd\n", r->ob_refcnt);
104104
v = PyLong_FromLong(1L); /* New reference. */
105105
/* PyTuple_SetItem steals the new reference v. */
106106
PyTuple_SetItem(r, 0, v);

tests/unit/test_c_exceptions.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24

35
from cPyExtPatt import cExceptions
@@ -9,6 +11,14 @@ def test_raise_error():
911
assert err.value.args[0] == 'Ooops.'
1012

1113

14+
@pytest.mark.skipif(sys.version_info.minor > 9, reason='Python <= 3.9')
15+
def test_raise_error_bad_old():
16+
with pytest.raises(SystemError) as err:
17+
cExceptions.raise_error_bad()
18+
assert err.value.args[0] == '<built-in function raise_error_bad> returned NULL without setting an error'
19+
20+
21+
@pytest.mark.skipif(sys.version_info.minor <= 9, reason='Python > 3.9')
1222
def test_raise_error_bad():
1323
with pytest.raises(SystemError) as err:
1424
cExceptions.raise_error_bad()
@@ -27,6 +37,14 @@ def test_raise_error_overwrite():
2737
assert err.value.args[0] == 'ERROR: raise_error_overwrite()'
2838

2939

40+
@pytest.mark.skipif(sys.version_info.minor > 9, reason='Python <= 3.9')
41+
def test_raise_error_silent_old():
42+
with pytest.raises(SystemError) as err:
43+
cExceptions.raise_error_silent()
44+
assert err.value.args[0] == '<built-in function raise_error_silent> returned a result with an error set'
45+
46+
47+
@pytest.mark.skipif(sys.version_info.minor <= 9, reason='Python > 3.9')
3048
def test_raise_error_silent():
3149
with pytest.raises(SystemError) as err:
3250
cExceptions.raise_error_silent()

0 commit comments

Comments
 (0)