Skip to content

Commit

Permalink
Support CPython 3.13 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpdani authored Oct 21, 2024
1 parent e887f1f commit 318061e
Show file tree
Hide file tree
Showing 31 changed files with 593 additions and 335 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ on:
pull_request:

jobs:
build:

lint:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: [ "nogil-3.9" ]
python-version: [ "3.13.0" ]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: set up python ${{ matrix.python-version }}
uses: dpdani/setup-python@nogil
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: check nogil
run: |
python -c "import sys; print(sys.flags.nogil);"
- name: install dependencies & cereggii
run: |
python -m pip install --upgrade pip
Expand All @@ -31,4 +28,4 @@ jobs:
run: black --check .
- name: lint
run: |
ruff .
ruff check .
11 changes: 4 additions & 7 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@ on:
types: [ published ]

jobs:
deploy:
publish:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "nogil-3.9" ]
python-version: [ "3.13.0" ]
permissions:
id-token: write # necessary for OIDC publishing https://docs.pypi.org/trusted-publishers/adding-a-publisher/
id-token: write # OIDC publishing https://docs.pypi.org/trusted-publishers/adding-a-publisher/

steps:
- uses: actions/checkout@v3
- name: set up python ${{ matrix.python-version }}
uses: dpdani/setup-python@nogil
with:
python-version: ${{ matrix.python-version }}
- name: check nogil
run: |
python -c "import sys; print(sys.flags.nogil);"
- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: build package
run: python -m build
- name: remove wheels # cannot yet publish wheels for free-threaded python
- name: remove wheels # TODO
run: rm dist/*.whl
- name: publish package
uses: pypa/gh-action-pypi-publish@release/v1
107 changes: 24 additions & 83 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,110 +6,51 @@ on:
pull_request:

jobs:
build:

runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [ "nogil-3.9" ]
os:
- ubuntu-latest
python-version:
- 3.13.0
- 3.13t

name: ${{ matrix.os }} / ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: set up python ${{ matrix.python-version }}
uses: dpdani/setup-python@nogil
uses: actions/setup-python@v5
if: "!endsWith(matrix.python-version, 't')"
with:
python-version: ${{ matrix.python-version }}
- name: set up python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@v3
if: endsWith(matrix.python-version, 't')
- if: endsWith(matrix.python-version, 't')
run: |
uv python install ${{ matrix.python-version }}
uv venv --python ${{ matrix.python-version }}
. .venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
uv pip install pip
- run: python --version --version && which python
- name: system info
run: |
uname -a
cat /proc/cpuinfo
- name: check nogil
run: |
python -c "import sys; print(sys.flags.nogil);"
- name: install dependencies & cereggii
run: |
python -m pip install --upgrade pip
pip -V
pip install .[dev]
- name: test with pytest
run: |
ulimit -c unlimited
ulimit -c
sudo mkdir -p /cores/
sudo mkdir -p ./so-libs
sudo chmod -R 777 /cores/
sudo chmod -R 777 ./so-libs
echo "/cores/core-%e-%p-%t" | sudo tee /proc/sys/kernel/core_pattern
sudo cat /proc/sys/kernel/core_pattern
pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml
if: ${{ always() }}
- name: prepare shared libs
run: |
declare -a shared=(
"$pythonLocation/lib/python3.9/site-packages/cereggii/_cereggii.so"
"$pythonLocation/lib/python3.9/lib-dynload/pyexpat.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_decimal.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/unicodedata.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_elementtree.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_datetime.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_sha512.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_random.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_json.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/math.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/select.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_posixsubprocess.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_struct.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_lzma.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_bz2.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/libpython3.9.so.1.0"
"$pythonLocation/lib/python3.9/lib-dynload/_uuid.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_bisect.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/grp.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/zlib.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/binascii.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_csv.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/lib/python3.9/lib-dynload/_heapq.nogil-39b-x86_64-linux-gnu.so"
"$pythonLocation/bin/python3.9"
"/usr/lib/locale/locale-archive"
"/usr/lib/x86_64-linux-gnu/libc.so.6"
"/lib/x86_64-linux-gnu/libz.so.1"
"/lib/x86_64-linux-gnu/libpthread.so.0"
"/lib/x86_64-linux-gnu/libdl.so.2"
"/lib/x86_64-linux-gnu/libutil.so.1"
"/lib/x86_64-linux-gnu/libm.so.6"
"/lib/x86_64-linux-gnu/libc.so.6"
"/usr/lib/x86_64-linux-gnu/libz.so.1.2.11"
"/usr/lib/locale/C.utf8/LC_CTYPE"
"/usr/lib/x86_64-linux-gnu/libm.so.6"
"/usr/lib/x86_64-linux-gnu/libutil.so.1"
"/usr/lib/x86_64-linux-gnu/libdl.so.2"
"/usr/lib/x86_64-linux-gnu/libpthread.so.0"
"/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache"
"/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2"
"/lib64/ld-linux-x86-64.so.2"
)
for f in "${shared[@]}"
do
mkdir -p $(dirname "./so-libs$f")
cp "$f" "./so-libs$f"
done
if: ${{ failure() }}
- name: upload core dump file
uses: actions/upload-artifact@v3
with:
name: core-dump
path: /cores
if: ${{ always() }}
- name: upload shared libs
uses: actions/upload-artifact@v3
with:
name: shared-libs
path: ./so-libs
if: ${{ always() }}
- name: upload pytest test results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/test-results-${{ matrix.python-version }}.xml
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cereggii

[![supports free-threading](https://github.com/dpdani/free-threading-badges/raw/main/supported.svg)](https://py-free-threading.github.io/)

Thread synchronization utilities for free-threaded Python.

This library provides some atomic data types which, in a multithreaded context, are generally more performant compared
Expand Down
24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "py_build_cmake.build"
name = "cereggii"
dynamic = ["version", "description"]
readme = "README.md"
requires-python = "~=3.9"
requires-python = ">=3.13"
license = { file = "LICENSE" }
authors = [
{ name = "dpdani", email = "[email protected]" },
Expand All @@ -16,11 +16,11 @@ keywords = [
"multithreading",
]
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Operating System :: OS Independent",
"Natural Language :: English",
Expand All @@ -29,11 +29,11 @@ dependencies = []

[project.optional-dependencies]
dev = [
"build==1.0.3",
"pytest==7.4.2",
"build==1.2.2.post1",
"pytest==8.3.3",
"pytest-reraise==2.1.2",
"black==23.9.1",
"ruff==0.0.292",
"black==24.10.0",
"ruff==0.7.0",
]


Expand All @@ -58,13 +58,15 @@ install_components = ["python_modules"]


[tool.black]
target-version = ["py39"]
target-version = ["py313"]
line-length = 120
skip-string-normalization = true

[tool.ruff]
target-version = "py39"
target-version = "py313"
line-length = 120

[lint]
select = [
"A",
"ARG",
Expand Down Expand Up @@ -112,11 +114,9 @@ unfixable = [
# Don't touch unused imports
"F401",
]

[tool.ruff.isort]
known-first-party = ["cereggii"]

[tool.ruff.per-file-ignores]
[lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]

Expand Down
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options("-mcx16")
add_compile_options("-msse4.2")

message("Python3_INCLUDE_DIR=" ${Python3_INCLUDE_DIR})
execute_process(COMMAND python -c "import sysconfig; print(sysconfig.get_path('include'), end='')" OUTPUT_VARIABLE Python3_INCLUDE_DIR)
message("Python3_INCLUDE_DIR=" ${Python3_INCLUDE_DIR})
find_package(Python3 REQUIRED COMPONENTS Development.Module)


Expand Down
9 changes: 0 additions & 9 deletions src/cereggii/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
Thread synchronization utilities for free-threaded Python.
"""

import sys
import warnings

from .__about__ import __license__, __version__, __version_tuple__ # noqa: F401
from .atomic_dict import AtomicDict # noqa: F401
from .atomic_int import AtomicInt, AtomicIntHandle # noqa: F401
from .atomic_ref import AtomicRef # noqa: F401
from .constants import * # noqa: F403


if not getattr(sys.flags, "nogil", False):
warnings.warn(
"this library is meant to be used with nogil python: https://github.com/colesbury/nogil", stacklevel=1
)
15 changes: 13 additions & 2 deletions src/cereggii/_cereggii.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterable, Iterator
from typing import Callable, NewType, SupportsComplex, SupportsFloat, SupportsInt
from collections.abc import Iterable, Iterator, Callable
from typing import NewType, SupportsComplex, SupportsFloat, SupportsInt

Key = NewType("Key", object)
Value = NewType("Value", object)
Expand Down Expand Up @@ -137,6 +137,7 @@ class AtomicDict:
:returns: the input :param:`batch` dictionary, with substituted values.
"""

def reduce(
self,
iterable: Iterable[tuple[Key, Value]],
Expand Down Expand Up @@ -167,6 +168,7 @@ class AtomicDict:
d.reduce(data, count)
"""

def compact(self) -> None: ...
def debug(self) -> dict: ...
def rehash(self, o: object) -> int: ...
Expand Down Expand Up @@ -197,26 +199,35 @@ class AtomicInt(int):
def get_handle(self) -> AtomicIntHandle: ...
def __itruediv__(self, other):
raise NotImplementedError

def as_integer_ratio(self):
raise NotImplementedError

def bit_length(self):
raise NotImplementedError

def conjugate(self):
raise NotImplementedError

@classmethod
def from_bytes(cls, *args, **kwargs):
raise NotImplementedError

def to_bytes(self, *args, **kwargs):
raise NotImplementedError

@property
def denominator(self):
raise NotImplementedError

@property
def numerator(self):
raise NotImplementedError

@property
def imag(self):
raise NotImplementedError

@property
def real(self):
raise NotImplementedError
Expand Down
Loading

0 comments on commit 318061e

Please sign in to comment.