Skip to content

Commit

Permalink
Build wheels for old Python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
AT0myks committed May 31, 2023
1 parent 52808e5 commit 936b260
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 15 deletions.
87 changes: 85 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,89 @@ jobs:
path: wheelhouse/*.whl
if-no-files-found: error

wheels-old:
name: Build old wheels on ${{ matrix.os }} for ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
arch: ["x86_64"]
include:
- os: windows-2019
arch: win_amd64
- os: windows-2019
arch: win32
- os: ubuntu-20.04
arch: i686
- os: ubuntu-20.04
arch: aarch64
- os: ubuntu-20.04
arch: ppc64le
- os: ubuntu-20.04
arch: s390x
exclude:
- os: windows-2019
arch: "x86_64"
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Build and test wheels
uses: pypa/cibuildwheel@v1.12.0
env:
CIBW_ARCHS: all
CIBW_BUILD_VERBOSITY: 3
CIBW_BUILD: "*${{ matrix.arch }}"
CIBW_SKIP: cp36-* cp37-* cp38-* cp39-* pp37-* pp*-macosx* cp35-macosx_x86_64
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: pytest {package}/tests
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-${{ matrix.arch }}
path: wheelhouse/*.whl
if-no-files-found: error

wheels-win27:
name: Build Python 2.7 wheels on Windows ${{ matrix.arch }}
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
arch: ["amd64", "win32"]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Prepare compiler environment for Windows
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
- name: Set Windows environment variables
if: runner.os == 'Windows'
shell: bash
run: |
echo "DISTUTILS_USE_SDK=1" >> $GITHUB_ENV
echo "MSSdk=1" >> $GITHUB_ENV
- name: Build and test wheels
uses: pypa/cibuildwheel@v1.12.0
env:
CIBW_BUILD_VERBOSITY: 3
CIBW_BUILD: "*27*${{ matrix.arch }}"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: pytest {package}/tests
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-${{ matrix.arch }}
path: wheelhouse/*.whl
if-no-files-found: error

sdist:
name: Build sdist
runs-on: ubuntu-latest
Expand Down Expand Up @@ -82,8 +165,8 @@ jobs:
publish:
name: Publish builds on PyPI
runs-on: ubuntu-latest
needs: [wheels, sdist]
if: ${{ always() && (needs.wheels.result == 'success' || needs.sdist.result == 'success') }}
needs: [sdist, wheels, wheels-old, wheels-win27]
if: ${{ always() && (needs.sdist.result == 'success' || needs.wheels.result == 'success' || needs.wheels-old.result == 'success' || needs.wheels-win27.result == 'success') }}
environment:
name: release
url: https://test.pypi.org/p/python-lzo
Expand Down
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ Once you are in the root of the project directory where `pyproject.toml` is loca
run `python -m build -w`. This should build a wheel in the `dist` directory.
You might need to install `build` with `pip install build`.

To build wheels targeting Python 3.6 or lower you should use v1.15 because
in newer versions of the project, the metadata has moved from `setup.py` to
`pyproject.toml` and these Python versions are not compatible with newer releases
of `pip` that correctly support `pyproject.toml`-based builds. You could also
manually move that metadata back to `setup.py`.

If you really want to build a wheel for Python 2.7 on Windows you'll need the
[Microsoft Visual C++ Compiler for Python 2.7](https://web.archive.org/web/20210116063838/https://www.microsoft.com/en-us/download/details.aspx?id=44266).

Expand All @@ -76,8 +70,8 @@ programs that ship with the LZO library.

# Python 2 support statement

As of 1.15, Python 2.x is unsupported. To continue using Python 2.6 or
Python 2.7, please stick with version 1.14.
Python 2.7 is still supported but without being a priority.
Support will be dropped soon.

# Notes

Expand All @@ -87,8 +81,8 @@ Python version that it can run tests for.

# Releasing

1. Update version in `pyproject.toml` and the `MODULE_VERSION` define in
`lzomodule.c`.
1. Update version in `pyproject.toml`, `setup.py` and the `MODULE_VERSION`
define in `lzomodule.c`.
1. Update NEWS.
1. Tag with new release.
1. wheels (download from github actions)
Expand Down
8 changes: 8 additions & 0 deletions lzomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ compress(PyObject *dummy, PyObject *args, PyObject *kwds)

/* init */
UNUSED(dummy);
#if PY_VERSION_HEX >= 0x03030000
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#|ii$s", argnames, &in, &len, &level, &header, &algorithm))
#else
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#|iis", argnames, &in, &len, &level, &header, &algorithm))
#endif
return NULL;
if (len < 0)
return NULL;
Expand Down Expand Up @@ -309,7 +313,11 @@ decompress(PyObject *dummy, PyObject *args, PyObject *kwds)

/* init */
UNUSED(dummy);
#if PY_VERSION_HEX >= 0x03030000
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#|ii$s", argnames, &in, &len, &header, &buflen, &algorithm))
#else
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#|iis", argnames, &in, &len, &header, &buflen, &algorithm))
#endif
return NULL;
if (header) {
if (len < 5 + 3 || in[0] < 0xf0 || in[0] > 0xf1)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Homepage = "https://github.com/jd-boyd/python-lzo"
[tool.cibuildwheel]
archs = ["all"]
build-verbosity = 3
skip = "cp36*"
test-requires = "pytest"
test-command = "pytest {package}/tests"
test-skip = "*-win_arm64 *-macosx_arm64 *-macosx_universal2:arm64"
18 changes: 18 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def run(self):
lzo_dir = os.environ.get("LZO_DIR", "lzo-2.10") # Relative path.

setup(
name="python-lzo",
version="1.15",
description="Python bindings for the LZO data compression library",
author="Markus F.X.J. Oberhumer",
author_email="markus@oberhumer.com",
maintainer="Joshua D. Boyd",
maintainer_email="jdboyd@jdboyd.net",
url="https://github.com/jd-boyd/python-lzo",
license="GNU General Public License (GPL)",
tests_require=['pytest'],
cmdclass={
"test": TestCommand
},
Expand All @@ -40,4 +50,12 @@ def run(self):
extra_link_args=["-flat_namespace"] if sys.platform == "darwin" else [],
)
],
long_description="""
This module provides Python bindings for the LZO data compression library.
LZO is a portable lossless data compression library written in ANSI C.
It offers pretty fast compression and *very* fast decompression.
Decompression requires no memory.
In addition there are slower compression levels achieving a quite
competitive compression ratio while still decompressing at
this very high speed.""",
)
11 changes: 9 additions & 2 deletions tests/test_lzo.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def gen_all(src):
raise lzo.error("internal error 1: %r %r", src, u1)
if a0 != a1:
raise lzo.error("internal error 2")
print(f"compressed using {algo} {len(src): 6} -> {len(c): 6}")
print("compressed using {} {:6} -> {:6}".format(algo, len(src), len(c)))


def gen_raw(src, level=1):
Expand Down Expand Up @@ -144,7 +144,14 @@ def test_lzo_big_raw():
gen_raw(b" " * 131072)


if sys.maxsize > 1<<32 and sys.implementation.name != "pypy":
def is_pypy():
if sys.version_info >= (3, 3):
return sys.implementation.name == "pypy"
else:
return "pypy" in sys.version.lower()


if sys.maxsize > 1<<32 and not is_pypy():
# This test raises OverflowError on 32-bit Pythons. Compressing
# this much data requires a 64-bit system.
# On PyPy it raises MemoryError.
Expand Down

0 comments on commit 936b260

Please sign in to comment.