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

fix: pure python build #94

Merged
merged 10 commits into from
Aug 2, 2024
8 changes: 5 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9"]
python-version: ["3.11"]
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -452,7 +452,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9"]
python-version: ["3.11"]
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -520,7 +520,7 @@ jobs:
# We use a regular Python matrix entry to share as much code as possible.
strategy:
matrix:
python-version: ["3.9"]
python-version: ["3.11"]
image: [manylinux2014_x86_64, manylinux2014_i686, manylinux2014_aarch64]

steps:
Expand Down Expand Up @@ -601,6 +601,8 @@ jobs:
name: manylinux_${{ matrix.image }}_wheels.zip
- name: Restore pip cache permissions
run: sudo chown -R $(whoami) ${{ steps.pip-cache-default.outputs.dir }}
- name: Prevent publishing wheels for unreleased Python versions
run: VER=$(echo '3.13' | tr -d .) && ls -al wheelhouse && sudo rm -f wheelhouse/*-cp${VER}*.whl && ls -al wheelhouse
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: >
Expand Down
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/zopefoundation/meta/tree/master/config/c-code
[meta]
template = "c-code"
commit-id = "b4846e99"
commit-id = "c412f00f"

[python]
with-appveyor = true
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read(fname):
is_pypy = py_impl() == 'PyPy'
is_jython = py_impl() == 'Jython'
is_pure = int(os.environ.get('PURE_PYTHON', '0'))
if is_pypy or is_jython:
if is_pure or is_pypy or is_jython:
ext_modules = []
else:
ext_modules = [Extension(name='zodbpickle._pickle',
Expand Down
6 changes: 5 additions & 1 deletion src/zodbpickle/fastpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


import sys
import warnings

from .pickle_3 import *

Expand All @@ -26,4 +27,7 @@

# isort: off
# also make sure that we really have the fast version
from ._pickle import * # noqa: E402 module level import not at top of file
if is_pure: # noqa: F405
warnings.warn("fastpickle imported under 'PURE_PYTHON' environment")
else:
from ._pickle import * # noqa: E402 module level import not at top of file
13 changes: 10 additions & 3 deletions src/zodbpickle/pickle_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import codecs
import io
import marshal
import os
import re
import struct
import sys
Expand All @@ -42,6 +43,8 @@
__all__ = ["PickleError", "PicklingError", "UnpicklingError", "Pickler",
"Unpickler", "dump", "dumps", "load", "loads"]

is_pure = int(os.environ.get('PURE_PYTHON', '0'))

# Shortcut for use in isinstance testing
bytes_types = (bytes, bytearray)
__all__.append('bytes_types')
Expand Down Expand Up @@ -1506,11 +1509,15 @@ def _loads(s, *, fix_imports=True, encoding="ASCII", errors="strict"):


# Use the faster _pickle if possible
try:
from zodbpickle._pickle import *
except ImportError:
if is_pure:
Pickler, Unpickler = _Pickler, _Unpickler
dump, dumps, load, loads = _dump, _dumps, _load, _loads
else:
try:
from zodbpickle._pickle import *
except ImportError:
Pickler, Unpickler = _Pickler, _Unpickler
dump, dumps, load, loads = _dump, _dumps, _load, _loads

# Doctest

Expand Down
12 changes: 8 additions & 4 deletions src/zodbpickle/tests/pickle_3_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
from .pickletester_3 import BigmemPickleTests


try:
from zodbpickle import _pickle
has_c_implementation = not _is_pypy and not _is_pure
except ImportError:
if not _is_pypy and not _is_pure:
try:
from zodbpickle import _pickle
except ImportError:
has_c_implementation = False
else:
has_c_implementation = True
else:
has_c_implementation = False


Expand Down
4 changes: 3 additions & 1 deletion src/zodbpickle/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import types
import unittest

from . import _is_pure
from . import _is_pypy


if _is_pypy:
if _is_pure or _is_pypy:
function_type = types.FunctionType
else:
function_type = types.BuiltinFunctionType
del sys
del _is_pypy
del _is_pure


class TestImportability(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ envlist =
coverage

[testenv]
usedevelop = true
pip_pre = py313: true
deps =
setuptools < 69
Expand All @@ -42,6 +41,7 @@ commands =
coverage run -m zope.testrunner --test-path=src {posargs:-vc}
coverage html -i
coverage report -i -m --fail-under=63

[testenv:release-check]
description = ensure that the distribution is ready to release
basepython = python3
Expand Down
Loading