Skip to content

Commit

Permalink
Version 0.13.0: Python 3.13 compatibility
Browse files Browse the repository at this point in the history
Python 3.13 removed _PyArg_ParseStack and _PyDict_SetItem_KnownHash from the C API

Unfortunately this means that the code has to resort to the old (not as optimized)
approaches again.

CI:
- Update pypy build
- Update python 3.12 build
- Add python 3.13 rc2 build
- update cibuildwheel
- fix mistake in url for pypy build
- fix missing artifacts for benchmarks

Misc:

- Fix numpydoc warnings
- Increase Python version that's linked in the docs
  • Loading branch information
MSeifert04 committed Oct 8, 2024
1 parent d3df1a7 commit fb458c1
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cpython-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: py3.12-benchmarks
path: ./.benchmark_results/
path: ./benchmark_results/
32 changes: 16 additions & 16 deletions .github/workflows/cpython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,45 @@ jobs:
run: |
python -m pytest tests/
build-python-with-debug:
build-python3-13-with-debug:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out source
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download Python 3.12
- name: Download Python
run: |
wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz -q
python3 ci/verify_checksum.py Python-3.12.2.tgz 4e64a004f8ad9af1a75607cfd0d5a8c8
- name: Install Python 3.12
wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz -q
python3 ci/verify_checksum.py Python-3.13.0.tgz c29f37220520ec6075fc37d4c62e178b
- name: Install Python
run: |
tar xzf Python-3.12.2.tgz
cd Python-3.12.2
tar xzf Python-3.13.0.tgz
cd Python-3.13.0
./configure --with-pydebug
sudo make altinstall -s -j2
- name: Remove download
run: |
sudo python3.12 -c "import os; os.remove('./Python-3.12.2.tgz'); import shutil; shutil.rmtree('./Python-3.12.2/')"
sudo python3.13 -c "import os; os.remove('./Python-3.13.0.tgz'); import shutil; shutil.rmtree('./Python-3.13.0/')"
- name: Install dependencies
run: |
python3.12 -m pip install pip setuptools wheel --upgrade --user --no-warn-script-location
python3.13 -m pip install pip setuptools wheel --upgrade --user --no-warn-script-location
- name: Create wheel
run: |
python3.12 -m pip wheel . --no-deps --wheel-dir=./wheelhouse/ -vv
python3.13 -m pip wheel . --no-deps --wheel-dir=./wheelhouse/ -vv
- name: Install package
run: |
python3.12 -m pip install iteration_utilities --no-index --find-links=./wheelhouse/ --user -vv
python3.13 -m pip install iteration_utilities --no-index --find-links=./wheelhouse/ --user -vv
- name: Import package
run: |
python3.12 -c "import iteration_utilities"
python3.13 -c "import iteration_utilities"
- name: Install test dependencies
run: |
python3.12 -m pip install pytest --user --no-warn-script-location
python3.13 -m pip install pytest --user --no-warn-script-location
- name: Run tests
run: |
python3.12 -m pytest tests/
python3.13 -m pytest tests/
build-sdist:
runs-on: ubuntu-latest
Expand All @@ -100,7 +100,7 @@ jobs:
rm ./dist/*.whl
- name: Install package
run: |
python -m pip install ./dist/iteration_utilities-0.12.1.tar.gz -vv
python -m pip install ./dist/iteration_utilities-0.13.0.tar.gz -vv
- name: Import package
run: |
python -c "import iteration_utilities"
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
python-version: '3.12'

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.16.5
run: python -m pip install cibuildwheel==2.21.2

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/pypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ jobs:
with:
fetch-depth: 1
- name: Test installation (Ubuntu)
if: matrix.os == 'ubuntu-20.04'
run: |
python3 -c "import urllib.request; urllib.request.urlretrieve ('hhttps://downloads.python.org/pypy/pypy3.10-v7.3.15-linux64.tar.bz2', './pypy.tar.bz2')"
python3 -c "import urllib.request; urllib.request.urlretrieve ('https://downloads.python.org/pypy/pypy3.10-v7.3.17-linux64.tar.bz2', './pypy.tar.bz2')"
python3 -c "import tarfile; tar = tarfile.open('./pypy.tar.bz2', 'r:bz2');tar.extractall('.'); tar.close()"
./pypy3.10-v7.3.15-linux64/bin/pypy3 -m ensurepip
./pypy3.10-v7.3.15-linux64/bin/pypy3 -m pip install pip setuptools --upgrade
./pypy3.10-v7.3.15-linux64/bin/pypy3 -m pip install . --no-deps -vv
./pypy3.10-v7.3.15-linux64/bin/pypy3 -c "import iteration_utilities"
./pypy3.10-v7.3.15-linux64/bin/pypy3 -m pip install pytest
./pypy3.10-v7.3.15-linux64/bin/pypy3 -m pytest tests
./pypy3.10-v7.3.17-linux64/bin/pypy3 -m ensurepip
./pypy3.10-v7.3.17-linux64/bin/pypy3 -m pip install pip setuptools --upgrade
./pypy3.10-v7.3.17-linux64/bin/pypy3 -m pip install . --no-deps -vv
./pypy3.10-v7.3.17-linux64/bin/pypy3 -c "import iteration_utilities"
./pypy3.10-v7.3.17-linux64/bin/pypy3 -m pip install pytest
./pypy3.10-v7.3.17-linux64/bin/pypy3 -m pytest tests
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.12"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
Expand Down
2 changes: 1 addition & 1 deletion ci/collect_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

if __name__ == '__main__':
benchmark_directory = pathlib.Path('./benchmarks/')
result_folder = pathlib.Path('./.benchmark_results/')
result_folder = pathlib.Path('./benchmark_results/')

# Create result folder and remove all png files there
result_folder.mkdir(exist_ok=True)
Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog for "iteration_utilities"
-----------------------------------

Version 0.13.0 (2024-10-08)
^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Python 3.13 compatibility: A few optimizations are not possible anymore in Python 3.13.
This means the performance of some functions (most notably ``groupedby``) will be slightly
slower.


Version 0.12.1 (2024-03-03)
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
# sphinx.ext.intersphinx
# #############################################################################

intersphinx_mapping = {'python': ('https://docs.python.org/3.8/', # target
intersphinx_mapping = {'python': ('https://docs.python.org/3.13/', # target
None), # inventory
}
# intersphinx_cache_limit
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "iteration_utilities"
version = "0.12.1"
version = "0.13.0"
description = "Utilities based on Pythons iterators and generators."
readme = "README.rst"
requires-python = ">=3.7"
Expand All @@ -22,6 +22,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
Expand Down
5 changes: 1 addition & 4 deletions src/iteration_utilities/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ class Iterable(_Base):
:py:meth:`~.Iterable.get_fsum` See :py:func:`math.fsum`.
:py:meth:`~.Iterable.get_geometric_mean` See :py:func:`statistics.geometric_mean`. (Python >= 3.8)
:py:meth:`~.Iterable.get_groupedby` See :py:func:`~iteration_utilities.groupedby`.
:py:meth:`~.Iterable.get_harmonic_mean` See :py:func:`statistics.harmonic_mean`. (Python >= 3.6)
:py:meth:`~.Iterable.get_harmonic_mean` See :py:func:`statistics.harmonic_mean`.
:py:meth:`~.Iterable.get_last` See :py:func:`~iteration_utilities.nth`.
:py:meth:`~.Iterable.get_max` See :py:func:`python:max`.
:py:meth:`~.Iterable.get_mean` See :py:func:`statistics.mean`.
Expand Down Expand Up @@ -1915,9 +1915,6 @@ def get_variance(self, mu=_default):
def get_harmonic_mean(self):
"""See :py:func:`statistics.harmonic_mean`.
.. note::
Python >= 3.6 is required for this function.
Examples
--------
>>> from iteration_utilities import Iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static PyMethodDef PyIU_methods[] = {
/* Helper */
{
"_parse_args", /* ml_name */
#if PyIU_USE_VECTORCALL
#if PyIU_USE_ARG_PARSE_STACK
(PyCFunction)(void (*)(void))PyIU_TupleToList_and_InsertItemAtIndex, /* ml_meth */
METH_FASTCALL, /* ml_flags */
#else
Expand All @@ -167,7 +167,7 @@ static PyMethodDef PyIU_methods[] = {
},
{
"_parse_kwargs", /* ml_name */
#if PyIU_USE_VECTORCALL
#if PyIU_USE_ARG_PARSE_STACK
(PyCFunction)(void (*)(void))PyIU_RemoveFromDictWhereValueIs, /* ml_meth */
METH_FASTCALL, /* ml_flags */
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ PyDoc_STRVAR(
" The first value.\n"
"\n"
"Raises\n"
"-------\n"
"------\n"
"ValueError :\n"
" If the `iterable` contains no items or more than one item.\n"
"\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ PyIU_parse_kwargs(PyObject *dct, PyObject *remvalue) {
Py_RETURN_NONE;
}

#if PyIU_USE_VECTORCALL
#if PyIU_USE_ARG_PARSE_STACK
PyObject *
PyIU_TupleToList_and_InsertItemAtIndex(PyObject *Py_UNUSED(m), PyObject *const *args, size_t nargs) {
PyObject *tup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {
#include <Python.h>
#include "helpercompat.h"

#if PyIU_USE_VECTORCALL
#if PyIU_USE_ARG_PARSE_STACK
PyObject * PyIU_TupleToList_and_InsertItemAtIndex(PyObject *Py_UNUSED(m), PyObject *const *args, size_t nargs);
PyObject * PyIU_RemoveFromDictWhereValueIs(PyObject *Py_UNUSED(m), PyObject *const *args, size_t nargs);
#else
Expand Down
2 changes: 0 additions & 2 deletions src/iteration_utilities/_iteration_utilities/groupedby.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "groupedby.h"
#include "helper.h"

#define PyIU_USE_DICT_INTERNALS PYIU_CPYTHON

PyObject *
PyIU_Groupby(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwargs) {
static char *kwlist[] = {"iterable", "key", "keep", "reduce", "reducestart", NULL};
Expand Down
3 changes: 3 additions & 0 deletions src/iteration_utilities/_iteration_utilities/helpercompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ extern "C" {
#define PyIU_USE_FASTCALL (PYIU_CPYTHON && PY_MAJOR_VERSION == 3 && (PY_MINOR_VERSION == 6 || PY_MINOR_VERSION == 7))
#define PyIU_USE_UNDERSCORE_VECTORCALL (PYIU_CPYTHON && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8)
#define PyIU_USE_VECTORCALL (PYIU_CPYTHON && ((PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || PY_MAJOR_VERSION >= 4))
#define PyIU_USE_ARG_PARSE_STACK (PYIU_CPYTHON && (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8 && PY_MINOR_VERSION < 13)) // https://github.com/python/cpython/issues/110964
#define PyIU_USE_BUILTIN_MODULE_ADDTYPE ((PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9) || PY_MAJOR_VERSION >= 4)

#define PyIU_USE_DICT_INTERNALS (PYIU_CPYTHON && (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13)) // https://github.com/python/cpython/pull/108449 and https://github.com/python/cpython/pull/112115

#ifdef Py_IS_TYPE
#define PyIU_USE_BUILTIN_IS_TYPE 1
#else
Expand Down
2 changes: 1 addition & 1 deletion src/iteration_utilities/_iteration_utilities/nth.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ PyDoc_STRVAR(
" If there is no such value then `default` is returned.\n"
"\n"
"Raises\n"
"-------\n"
"------\n"
"TypeError :\n"
" If there is no nth element and no `default` is given.\n"
"\n"
Expand Down
2 changes: 1 addition & 1 deletion src/iteration_utilities/_iteration_utilities/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ PyDoc_STRVAR(
" Generator containing the splitted `iterable` (lists).\n"
"\n"
"Raises\n"
"-------\n"
"------\n"
"TypeError\n"
" If ``maxsplit`` is smaller than ``-2``. If more than one of the ``keep``\n"
" arguments is ``True``.\n"
Expand Down

0 comments on commit fb458c1

Please sign in to comment.