Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.11 Abi3 wheels #479

Merged
merged 30 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cc4f184
add wheels for python 3.12 and update ci
waahm7 May 22, 2023
62bbc38
fix version
waahm7 Jun 7, 2023
c0c261f
fix wrap_socket
waahm7 Jun 7, 2023
db0ed31
update api for stable 311 api
waahm7 Jun 8, 2023
f4511ff
remove 312 wheel
waahm7 Jun 8, 2023
5e65e02
lint fix
waahm7 Jun 8, 2023
66bd959
fix mem leaks
waahm7 Jun 8, 2023
6042562
update builder
waahm7 Jun 8, 2023
70a039b
revert ubuntu
waahm7 Jun 8, 2023
3785f8f
latest submodule
waahm7 Jun 8, 2023
3796a83
Better DecRef
waahm7 Jun 9, 2023
2c81423
Merge branch 'main' into python-312
waahm7 Jun 12, 2023
232e556
lint fix
waahm7 Jun 12, 2023
6998ab6
Adds steal reference comment
waahm7 Jun 12, 2023
b87e909
add comments
waahm7 Jun 12, 2023
1ca818e
fix append function
waahm7 Jun 12, 2023
1260521
lint fix
waahm7 Jun 12, 2023
b4cd04b
Update source/http_headers.c
waahm7 Jun 12, 2023
5540a0d
Update source/mqtt5_client.c
waahm7 Jun 12, 2023
0e85cd6
Update source/mqtt5_client.c
waahm7 Jun 12, 2023
884289e
Update source/mqtt_client_connection.c
waahm7 Jun 12, 2023
61270a6
Update source/mqtt_client_connection.c
waahm7 Jun 12, 2023
bf8e02a
Update source/mqtt_client_connection.c
waahm7 Jun 12, 2023
b59045d
Update source/mqtt_client_connection.c
waahm7 Jun 12, 2023
4015a94
Update source/mqtt5_client.c
waahm7 Jun 12, 2023
8ff4f03
Update source/mqtt5_client.c
waahm7 Jun 12, 2023
2550900
PR feedback
waahm7 Jun 12, 2023
ad41140
update builder
waahm7 Jun 12, 2023
b9e356b
update variable name
waahm7 Jun 12, 2023
19df8c3
MuslLinux Wheels (#480)
waahm7 Jun 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'docs'

env:
BUILDER_VERSION: v0.9.45
BUILDER_VERSION: v0.9.46
BUILDER_SOURCE: releases
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
PACKAGE_NAME: aws-crt-python
Expand Down Expand Up @@ -52,6 +52,7 @@ jobs:
- cp39-cp39
- cp310-cp310
- cp311-cp311
- cp312-cp312
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
steps:
# Only aarch64 needs this, but it doesn't hurt anything
- name: Install qemu/docker
Expand Down Expand Up @@ -82,7 +83,7 @@ jobs:


linux-compat:
runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-22.04 # latest
strategy:
matrix:
image:
Expand All @@ -99,7 +100,7 @@ jobs:


linux-compiler-compat:
runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-22.04 # latest
strategy:
matrix:
compiler:
Expand Down Expand Up @@ -156,7 +157,7 @@ jobs:


osx:
runs-on: macos-11 # latest
runs-on: macos-13 # latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
Expand Down Expand Up @@ -211,7 +212,7 @@ jobs:

# check that tests requiring custom env-vars or AWS credentials are simply skipped
tests-ok-without-env-vars:
runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-22.04 # latest
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -228,7 +229,7 @@ jobs:
python3 -m unittest discover --failfast --verbose

package-source:
runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-22.04 # latest
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -242,7 +243,7 @@ jobs:

# check that docs can still build
check-docs:
runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-22.04 # latest
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -254,7 +255,7 @@ jobs:
./scripts/make-docs.py

check-submodules:
runs-on: ubuntu-20.04 # latest
runs-on: ubuntu-22.04 # latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion crt/aws-c-s3
2 changes: 1 addition & 1 deletion crt/s2n
Submodule s2n updated from 9b7b1f to b9c4d6
26 changes: 22 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
import subprocess
import sys
import sysconfig
from wheel.bdist_wheel import bdist_wheel


def is_64bit():
return sys.maxsize > 2**32
return sys.maxsize > 2 ** 32


def is_32bit():
Expand Down Expand Up @@ -152,7 +153,6 @@ def __init__(self, name, extra_cmake_args=[], libname=None):
AWS_LIBS.append(AwsLib('aws-c-mqtt'))
AWS_LIBS.append(AwsLib('aws-c-s3'))


PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))

VERSION_RE = re.compile(r""".*__version__ = ["'](.*?)['"]""", re.S)
Expand Down Expand Up @@ -283,11 +283,23 @@ def run(self):
super().run()


class bdist_wheel_abi3(bdist_wheel):
def get_tag(self):
python, abi, plat = super().get_tag()
if python.startswith("cp") and sys.version_info >= (3, 11):
# on CPython, our wheels are abi3 and compatible back to 3.11
return "cp311", "abi3", plat

return python, abi, plat
graebm marked this conversation as resolved.
Show resolved Hide resolved


def awscrt_ext():
# fetch the CFLAGS/LDFLAGS from env
extra_compile_args = os.environ.get('CFLAGS', '').split()
extra_link_args = os.environ.get('LDFLAGS', '').split()
extra_objects = []
define_macros = []
py_limited_api = False

libraries = [x.libname for x in AWS_LIBS]

Expand Down Expand Up @@ -350,14 +362,20 @@ def awscrt_ext():
if not is_macos_universal2():
extra_link_args += ['-Wl,-fatal_warnings']

if sys.version_info >= (3, 11):
define_macros.append(('Py_LIMITED_API', '0x030B0000'))
py_limited_api = True

return setuptools.Extension(
'_awscrt',
language='c',
libraries=libraries,
sources=glob.glob('source/*.c'),
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
extra_objects=extra_objects
extra_objects=extra_objects,
define_macros=define_macros,
py_limited_api=py_limited_api,
)


Expand Down Expand Up @@ -392,6 +410,6 @@ def _load_version():
],
python_requires='>=3.7',
ext_modules=[awscrt_ext()],
cmdclass={'build_ext': awscrt_build_ext},
cmdclass={'build_ext': awscrt_build_ext, "bdist_wheel": bdist_wheel_abi3},
test_suite='test',
)
11 changes: 7 additions & 4 deletions source/auth_credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ PyObject *aws_py_credentials_provider_new_chain(PyObject *self, PyObject *args)
if (!providers_pyseq) {
goto done;
}
size_t provider_count = (size_t)PySequence_Fast_GET_SIZE(providers_pyseq);
size_t provider_count = (size_t)PySequence_Size(providers_pyseq);
if (provider_count == 0) {
PyErr_SetString(PyExc_ValueError, "Must supply at least one AwsCredentialsProvider.");
goto done;
Expand All @@ -526,8 +526,9 @@ PyObject *aws_py_credentials_provider_new_chain(PyObject *self, PyObject *args)
}

for (size_t i = 0; i < provider_count; ++i) {
PyObject *provider_py = PySequence_Fast_GET_ITEM(providers_pyseq, i);
PyObject *provider_py = PySequence_GetItem(providers_pyseq, i); /* new reference */
providers_carray[i] = aws_py_get_credentials_provider(provider_py);
Py_XDECREF(provider_py);
if (!providers_carray[i]) {
goto done;
}
Expand Down Expand Up @@ -724,7 +725,7 @@ PyObject *aws_py_credentials_provider_new_cognito(PyObject *self, PyObject *args
goto done;
}

logins_count = (size_t)PySequence_Fast_GET_SIZE(logins_pyseq);
logins_count = (size_t)PySequence_Size(logins_pyseq);
if (logins_count > 0) {

logins_carray =
Expand All @@ -735,7 +736,7 @@ PyObject *aws_py_credentials_provider_new_cognito(PyObject *self, PyObject *args
}

for (size_t i = 0; i < logins_count; ++i) {
PyObject *login_tuple_py = PySequence_Fast_GET_ITEM(logins_pyseq, i);
PyObject *login_tuple_py = PySequence_GetItem(logins_pyseq, i); /* New reference */
struct aws_cognito_identity_provider_token_pair *login_entry = &logins_carray[i];
AWS_ZERO_STRUCT(*login_entry);

Expand All @@ -750,8 +751,10 @@ PyObject *aws_py_credentials_provider_new_cognito(PyObject *self, PyObject *args
PyExc_TypeError,
"cognito credentials provider: logins[%zu] is invalid, should be type (str, str)",
i);
Py_XDECREF(login_tuple_py);
goto done;
}
Py_XDECREF(login_tuple_py);
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions source/event_stream_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,20 @@ bool aws_py_event_stream_native_headers_init(struct aws_array_list *native_heade
bool success = false;
PyObject *sequence_py = NULL;

sequence_py = PySequence_Fast(headers_py, "Expected sequence of Headers"); /* New reference */
sequence_py = PySequence_Fast(headers_py, "Expected sequence of Headers");
if (!sequence_py) {
goto done;
}

const Py_ssize_t count = PySequence_Fast_GET_SIZE(sequence_py);
const Py_ssize_t count = PySequence_Size(sequence_py);
for (Py_ssize_t i = 0; i < count; ++i) {
/* Borrowed reference, don't need to decref */
PyObject *header_py = PySequence_Fast_GET_ITEM(sequence_py, i);
PyObject *header_py = PySequence_GetItem(sequence_py, i); /* New Reference */

if (!s_add_native_header(native_headers, header_py)) {
Py_XDECREF(header_py);
goto done;
}
Py_XDECREF(header_py);
}

success = true;
Expand Down Expand Up @@ -270,7 +271,7 @@ PyObject *aws_py_event_stream_python_headers_create(
goto error;
}

PyList_SET_ITEM(list_py, i, tuple_py); /* steals reference to tuple */
PyList_SetItem(list_py, i, tuple_py); /* steals reference to tuple */
}

return list_py;
Expand Down
50 changes: 30 additions & 20 deletions source/http_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ PyObject *aws_py_http_headers_add(PyObject *self, PyObject *args) {
Py_RETURN_NONE;
}

static bool s_py_http_headers_add_pair(PyObject *py_pair, struct aws_http_headers *headers) {

const char *type_errmsg = "List of (name,value) pairs expected.";
if (!PyTuple_Check(py_pair) || PyTuple_Size(py_pair) != 2) {
PyErr_SetString(PyExc_TypeError, type_errmsg);
return false;
}

struct aws_byte_cursor name = aws_byte_cursor_from_pyunicode(PyTuple_GetItem(py_pair, 0) /* Borrowed reference */);
struct aws_byte_cursor value = aws_byte_cursor_from_pyunicode(PyTuple_GetItem(py_pair, 1) /* Borrowed reference */);
if (!name.ptr || !value.ptr) {
PyErr_SetString(PyExc_TypeError, type_errmsg);
return false;
}

if (aws_http_headers_add(headers, name, value)) {
PyErr_SetAwsLastError();
return false;
}

return true;
}

PyObject *aws_py_http_headers_add_pairs(PyObject *self, PyObject *args) {
PyObject *py_pairs;
S_HEADERS_METHOD_START("O", &py_pairs);
Expand All @@ -96,25 +119,12 @@ PyObject *aws_py_http_headers_add_pairs(PyObject *self, PyObject *args) {
return NULL;
}

const Py_ssize_t count = PySequence_Fast_GET_SIZE(py_sequence);
const Py_ssize_t count = PySequence_Size(py_pairs);
for (Py_ssize_t i = 0; i < count; ++i) {
/* XYZ_GET_ITEM() calls returns borrowed references */
PyObject *py_pair = PySequence_Fast_GET_ITEM(py_sequence, i);

if (!PyTuple_Check(py_pair) || PyTuple_GET_SIZE(py_pair) != 2) {
PyErr_SetString(PyExc_TypeError, type_errmsg);
goto done;
}

struct aws_byte_cursor name = aws_byte_cursor_from_pyunicode(PyTuple_GET_ITEM(py_pair, 0));
struct aws_byte_cursor value = aws_byte_cursor_from_pyunicode(PyTuple_GET_ITEM(py_pair, 1));
if (!name.ptr || !value.ptr) {
PyErr_SetString(PyExc_TypeError, type_errmsg);
goto done;
}

if (aws_http_headers_add(headers, name, value)) {
PyErr_SetAwsLastError();
PyObject *py_pair = PySequence_GetItem(py_sequence, i); /* New Reference */
bool success = s_py_http_headers_add_pair(py_pair, headers);
Py_DECREF(py_pair);
if (!success) {
goto done;
}
}
Expand Down Expand Up @@ -175,8 +185,8 @@ static PyObject *s_py_tuple_from_header(struct aws_http_header header) {
goto error;
}

PyTuple_SET_ITEM(py_pair, 0, py_name);
PyTuple_SET_ITEM(py_pair, 1, py_value);
PyTuple_SetItem(py_pair, 0, py_name); /* Steals a reference */
PyTuple_SetItem(py_pair, 1, py_value); /* Steals a reference */
return py_pair;

error:
Expand Down
2 changes: 1 addition & 1 deletion source/http_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int s_on_incoming_header_block_done(
goto done;
}

PyList_SET_ITEM(header_list, i, tuple); /* steals reference to tuple */
PyList_SetItem(header_list, i, tuple); /* steals reference to tuple */
waahm7 marked this conversation as resolved.
Show resolved Hide resolved
}

/* TODO: handle informational and trailing headers */
Expand Down
15 changes: 3 additions & 12 deletions source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,30 +531,21 @@ void *aws_py_get_binding(PyObject *obj, const char *capsule_name, const char *cl

PyObject *py_binding = PyObject_GetAttrString(obj, "_binding"); /* new reference */
if (!py_binding) {
return PyErr_Format(
PyExc_TypeError,
"Expected valid '%s', received '%s' (no '_binding' attribute)",
class_name,
Py_TYPE(obj)->tp_name);
return PyErr_Format(PyExc_TypeError, "Expected valid '%s' (no '_binding' attribute)", class_name);
}

void *binding = NULL;
if (!PyCapsule_CheckExact(py_binding)) {
PyErr_Format(
PyExc_TypeError,
"Expected valid '%s', received '%s' ('_binding' attribute is not a capsule)",
class_name,
Py_TYPE(obj)->tp_name);
PyErr_Format(PyExc_TypeError, "Expected valid '%s' ('_binding' attribute is not a capsule)", class_name);
goto done;
}

binding = PyCapsule_GetPointer(py_binding, capsule_name);
if (!binding) {
PyErr_Format(
PyExc_TypeError,
"Expected valid '%s', received '%s' ('_binding' attribute does not contain '%s')",
"Expected valid '%s' ('_binding' attribute does not contain '%s')",
class_name,
Py_TYPE(obj)->tp_name,
capsule_name);
goto done;
}
Expand Down
Loading
Loading