Skip to content

Commit

Permalink
Add support for Python 3.12. (#235)
Browse files Browse the repository at this point in the history
* Isort imports.
* Fix PyPy3 tests + remove some Py2 leftovers.
  • Loading branch information
icemac committed Nov 17, 2023
1 parent e563781 commit c3d9fbf
Show file tree
Hide file tree
Showing 62 changed files with 356 additions and 187 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ jobs:
- ["ubuntu", "ubuntu-20.04"]
config:
# [Python version, tox env]
- ["3.9", "release-check"]
- ["3.9", "lint"]
- ["3.7", "py37"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["3.12.0-beta.4", "py312"]
- ["3.12", "py312"]
- ["pypy-3.9", "pypy3"]
- ["3.9", "docs"]
- ["3.9", "coverage"]
Expand Down
5 changes: 3 additions & 2 deletions .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[meta]
template = "pure-python"
commit-id = "49beb029"
commit-id = "cb0568c7"

[python]
with-windows = false
with-pypy = true
with-future-python = true
with-future-python = false
with-docs = true
with-sphinx-doctests = false
with-macos = false
Expand Down Expand Up @@ -44,6 +44,7 @@ fail-under = 53

[manifest]
additional-rules = [
"include *.yaml",
"include *.py",
"include COPYING",
"include log.ini",
Expand Down
25 changes: 25 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# We recommend specifying your dependencies to enable reproducible builds:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
8 changes: 5 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog

- Drop support for Python 2.7, 3.5, 3.6.

- Add support for Python 3.12.

- Switch to using `async/await` directly instead of `@coroutine/yield`

- Drop experimental support for credentials object: the corresponding
Expand All @@ -16,12 +18,12 @@ Changelog
``password`` - support for such basic auth was dropped in 2016 before ZEO 5.0
was released.

- fix problems with Python 3.12.0b4
- Fix problems with Python 3.12.0b4
(`issue 231 <https://github.com/zopefoundation/ZEO/issues/231>_`).

- ensure test compatibility with both ``ZODB<6`` and ``ZODB>=6``
- Ensure test compatibility with both ``ZODB<6`` and ``ZODB>=6``
by looking for ZODB inherited tests with prefixes
``check`` (used by ``ZODB<6``)
``check`` (used by ``ZODB<6``)
and ``test`` (used by ``ZODB>=6``)
(`issue 233 <https://github.com/zopefoundation/ZEO/issues/233>_`).

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ recursive-include docs *.txt
recursive-include docs Makefile

recursive-include src *.py
include *.yaml
include *.py
include COPYING
include log.ini
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#
##############################################################################

from setuptools import setup, find_packages
from setuptools import find_packages
from setuptools import setup


version = '6.0.0.dev0'

Expand Down Expand Up @@ -67,6 +69,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Database",
Expand Down
11 changes: 5 additions & 6 deletions src/ZEO/ClientStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,28 @@
import stat
import sys
import threading
from threading import get_ident
import time
import weakref
from binascii import hexlify
from threading import get_ident

import BTrees.OOBTree

import zc.lockfile
import ZODB
import ZODB.BaseStorage
import ZODB.ConflictResolution
import ZODB.interfaces
import zope.interface

from persistent.TimeStamp import TimeStamp
from ZEO._compat import WIN
from ZEO.Exceptions import ClientDisconnected
from ZEO.TransactionBuffer import TransactionBuffer
from ZODB import POSException
from ZODB import utils

import ZEO.asyncio.client
import ZEO.cache
from ZEO._compat import WIN
from ZEO.Exceptions import ClientDisconnected
from ZEO.TransactionBuffer import TransactionBuffer


logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion src/ZEO/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""Exceptions for ZEO."""

import transaction.interfaces

from ZODB.POSException import StorageError


Expand Down
27 changes: 20 additions & 7 deletions src/ZEO/StorageServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,34 @@
import threading
import time
import warnings

import ZODB.blob
import ZODB.event
import ZODB.serialize
import ZODB.TimeStamp
import zope.interface

from ZEO._compat import Pickler, Unpickler
from ZEO.monitor import StorageStats
from ZEO.asyncio.server import Delay, MTDelay, Result, Acceptor
from ZODB.Connection import TransactionMetaData
from ZODB.loglevels import BLATHER
from ZODB.POSException import StorageError, StorageTransactionError
from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError
from ZODB.POSException import ConflictError
from ZODB.POSException import ReadOnlyError
from ZODB.POSException import StorageError
from ZODB.POSException import StorageTransactionError
from ZODB.POSException import TransactionError
from ZODB.serialize import referencesf
from ZODB.utils import p64, u64, z64, Lock, RLock
from ZODB.utils import Lock
from ZODB.utils import RLock
from ZODB.utils import p64
from ZODB.utils import u64
from ZODB.utils import z64

from ZEO._compat import Pickler
from ZEO._compat import Unpickler
from ZEO.asyncio.server import Acceptor
from ZEO.asyncio.server import Delay
from ZEO.asyncio.server import MTDelay
from ZEO.asyncio.server import Result
from ZEO.monitor import StorageStats


# multi-threaded acceptor was opt-in option, but later was deprecated and
# removed. Warn users that try to activate multi-threaded server mode to
Expand Down
3 changes: 2 additions & 1 deletion src/ZEO/TransactionBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

import tempfile

from ZEO._compat import Pickler, Unpickler
from ZEO._compat import Pickler
from ZEO._compat import Unpickler


class TransactionBuffer:
Expand Down
7 changes: 4 additions & 3 deletions src/ZEO/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
##############################################################################
"""Python versions compatiblity
"""
import sys
import platform
import sys

from zodbpickle.pickle import Pickler
from zodbpickle.pickle import Unpickler as _Unpickler
from zodbpickle.pickle import dump
from zodbpickle.pickle import dumps
from zodbpickle.pickle import loads
from zodbpickle.pickle import Pickler
from zodbpickle.pickle import Unpickler as _Unpickler


PYPY = getattr(platform, 'python_implementation', lambda: None)() == 'PyPy'
WIN = sys.platform.startswith('win')
Expand Down
9 changes: 5 additions & 4 deletions src/ZEO/_forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
##############################################################################
"""Library for forking storage server and connecting client storage"""
import gc
import logging
import multiprocessing
import os
import os.path
import sys
import multiprocessing
import logging
import tempfile
from io import StringIO

from queue import Empty


logger = logging.getLogger('ZEO.tests.forker')
DEBUG = os.environ.get('ZEO_TEST_SERVER_DEBUG')

Expand Down Expand Up @@ -109,6 +109,7 @@ def runner(config, qin, qout, timeout=None,

try:
import threading

from . import runzeo

options = runzeo.ZEOOptions()
Expand Down Expand Up @@ -224,8 +225,8 @@ def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
fp.write(zeo_conf)

if threaded:
from threading import Thread
from queue import Queue
from threading import Thread
else:
# Experimental to see whether server logging problems under MacOS
# have to do with its default `spawn` method
Expand Down
2 changes: 2 additions & 0 deletions src/ZEO/asyncio/_futures.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Please see its docstring for details.
"""

import asyncio


cdef object CancelledError = asyncio.CancelledError
cdef object InvalidStateError = asyncio.InvalidStateError
cdef object get_event_loop = asyncio.get_event_loop
Expand Down
1 change: 1 addition & 0 deletions src/ZEO/asyncio/_smp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from libc.string cimport memcpy
import logging
import struct


logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion src/ZEO/asyncio/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
The ZEO protocol has client and server variants.
"""
from asyncio import Protocol
import logging
from asyncio import Protocol

from .smp import SizedMessageProtocol


logger = logging.getLogger(__name__)


Expand Down
13 changes: 9 additions & 4 deletions src/ZEO/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@
import ZODB.POSException

import ZEO.Exceptions
from ZEO.Exceptions import ClientDisconnected, ServerException
import ZEO.interfaces
from ZEO.Exceptions import ClientDisconnected
from ZEO.Exceptions import ServerException

from . import base
from .compat import new_event_loop
from .marshal import encoder, decoder
from .futures import Future, AsyncTask as Task, \
run_coroutine_threadsafe, switch_thread
from .futures import AsyncTask as Task
from .futures import Future
from .futures import run_coroutine_threadsafe
from .futures import switch_thread
from .marshal import decoder
from .marshal import encoder


logger = logging.getLogger(__name__)

Expand Down
10 changes: 7 additions & 3 deletions src/ZEO/asyncio/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"""

import asyncio
from asyncio import CancelledError, InvalidStateError, get_event_loop
from asyncio import CancelledError
from asyncio import InvalidStateError
from asyncio import get_event_loop
from threading import Event
from time import sleep

Expand Down Expand Up @@ -357,8 +359,10 @@ def _cancel(self, msg):

# use C implementation if available
try:
from ._futures import Future, ConcurrentFuture # noqa: F401, F811
from ._futures import AsyncTask, ConcurrentTask # noqa: F401, F811
from ._futures import AsyncTask # noqa: F401, F811
from ._futures import ConcurrentFuture
from ._futures import ConcurrentTask
from ._futures import Future
from ._futures import switch_thread # noqa: F401, F811
except ImportError:
pass
Expand Down
4 changes: 3 additions & 1 deletion src/ZEO/asyncio/marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import logging
from io import BytesIO

from .._compat import Unpickler, Pickler
from .._compat import Pickler
from .._compat import Unpickler
from ..shortrepr import short_repr


logger = logging.getLogger(__name__)


Expand Down
6 changes: 4 additions & 2 deletions src/ZEO/asyncio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import logging
import os
import threading

import ZODB.POSException

from ..shortrepr import short_repr

from . import base
from .compat import new_event_loop
from .marshal import server_decoder, encoder, reduce_exception
from .marshal import encoder
from .marshal import reduce_exception
from .marshal import server_decoder


logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion src/ZEO/asyncio/smp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
by the message's bytes.
"""

import struct
from asyncio import Protocol
from logging import getLogger
import struct


logger = getLogger(__name__)

Expand Down

0 comments on commit c3d9fbf

Please sign in to comment.