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

Add support for Python's "Limited API"; Test cibuildwheel and py >=3.5 using TestPythonSML.py #461

Merged
merged 14 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
14 changes: 12 additions & 2 deletions Core/ClientSMLSWIG/Python/Python_sml_ClientInterface.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// handle windows calling convention, __declspec(dllimport), correctly
%include <windows.i>

%begin %{
#define Py_LIMITED_API 0x03050000
ShadowJonathan marked this conversation as resolved.
Show resolved Hide resolved
%}

%{
// helps quell warnings
#ifndef unused
Expand Down Expand Up @@ -252,7 +256,10 @@
return "";
}

std::string res = PyUnicode_AsUTF8 (result);
PyObject* unicode = PyUnicode_AsUTF8String (result);
std::string res = PyBytes_AsString(unicode);

Py_DECREF(unicode);
Py_DECREF(result);

PyGILState_Release(gstate); /* Release the thread. No Python API allowed beyond this point. */
Expand Down Expand Up @@ -303,7 +310,10 @@
return "";
}

std::string res = PyUnicode_AsUTF8 (result);
PyObject* unicode = PyUnicode_AsUTF8String (result);
std::string res = PyBytes_AsString(unicode);

Py_DECREF(unicode);
Py_DECREF(result);

PyGILState_Release(gstate); /* Release the thread. No Python API allowed beyond this point. */
Expand Down
2 changes: 1 addition & 1 deletion Core/ClientSMLSWIG/Python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ requires = [
# and other python build/install frontends (such as pip itself).
#
# We use a forked version of enscons to add python 3.12 support.
"enscons @ git+https://github.com/ShadowJonathan/enscons-soar@544f39f",
"enscons @ git+https://github.com/ShadowJonathan/enscons-soar@190091866ac35fb5d390c425bafaf13443baee5e",

# Required sub-dependencies of enscons.
"toml>=0.1",
Expand Down
4 changes: 3 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,13 @@ py_sources += [
env.Alias(SML_PYTHON_ALIAS + "_dev", py_sources)

if enscons_active:
env['PACKAGE_METADATA'] = enscons.get_pyproject(env)['project']
# Instead of giving an explicit tag, we tell enscons that we're not building a "pure" (python-only) library,
# and so we let it determine the wheel tag by itself.
env['ROOT_IS_PURELIB'] = False

# This enables tagging the wheel with the limited api, and also sets the target python version.
env["LIMITED_API_TARGET"] = (3, 5)
ShadowJonathan marked this conversation as resolved.
Show resolved Hide resolved

# Whl and WhlFile add multiple targets (sdist, dist_info, bdist_wheel, editable) to env
# for enscons (python build backend for scons; required for building with cibuildwheel).
whl = env.Whl("platlib", py_sources, root="")
Expand Down