From 3762936c38c85c86f67a5b265fd0766b46d7392d Mon Sep 17 00:00:00 2001 From: "Joshua D. Boyd" Date: Thu, 4 Jun 2026 02:11:46 -0400 Subject: [PATCH] Remove outdate wheel building file, and work on windows and linux wheel building. New linux build workflow. Uses lzo source like windows does if liblzo2 isn't found. Clean up windows a bit more, add arm64. Remove MSBuild step since it is now redundant. --- .github/workflows/build-linux.yml | 82 +++++++++++++++++++++ .github/workflows/build-macos.yml | 32 +++++++- .github/workflows/build-windows.yml | 67 ++++++++++------- .github/workflows/wheels.yml | 109 ---------------------------- setup.py | 33 ++++++++- 5 files changed, 185 insertions(+), 138 deletions(-) create mode 100644 .github/workflows/build-linux.yml delete mode 100644 .github/workflows/wheels.yml diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml new file mode 100644 index 0000000..85e298f --- /dev/null +++ b/.github/workflows/build-linux.yml @@ -0,0 +1,82 @@ +name: Build wheels for Linux + +on: + workflow_dispatch: + inputs: + publish_to_testpypi: + description: 'Publish wheels/sdist to TestPyPI' + type: boolean + default: false + push: + tags: + - v* + +jobs: + build-wheels: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v6 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Build wheels + uses: pypa/cibuildwheel@v2 + env: + CIBW_ARCHS_LINUX: "x86_64 i686 aarch64 ppc64le s390x armv7l" + CIBW_TEST_COMMAND: "python -c \"import lzo; d=b'test'*42; assert lzo.decompress(lzo.compress(d))==d\"" + + - name: Upload wheels + uses: actions/upload-artifact@v6 + with: + name: wheels-linux + path: wheelhouse/*.whl + if-no-files-found: error + + sdist: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v6 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.8" + + - name: Build sdist + run: | + python -m pip install --upgrade pip build + python -m build -s + + - name: Upload sdist + uses: actions/upload-artifact@v6 + with: + name: sdist + path: dist/*.tar.gz + if-no-files-found: error + + publish-testpypi: + name: Publish to TestPyPI + needs: [build-wheels, sdist] + if: inputs.publish_to_testpypi + runs-on: ubuntu-latest + environment: + name: release + url: https://test.pypi.org/p/python-lzo + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v6 + with: + path: dist + - run: | + mv dist/*/*.whl dist/ 2>/dev/null || true + mv dist/*/*.tar.gz dist/ 2>/dev/null || true + find dist -mindepth 1 -type d -delete + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index f1373ef..29cccd6 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -14,6 +14,13 @@ on: required: false type: string default: "" + publish_to_testpypi: + description: 'Publish wheels to TestPyPI' + type: boolean + default: false + push: + tags: + - v* permissions: contents: write # required to create tags, releases @@ -56,8 +63,8 @@ jobs: - "3.13" - "3.14" os: - - macos-14 - - macos-15 # currently (2026) same as macos-latest + - macos-13 + - macos-latest name: "Python ${{ matrix.python-version }}" steps: - name: Checkout repo @@ -202,3 +209,24 @@ jobs: --title "${TAG}" \ --generate-notes fi + + publish-testpypi: + name: Publish to TestPyPI + needs: [build] + if: inputs.publish_to_testpypi && needs.build.result == 'success' + runs-on: ubuntu-latest + environment: + name: release + url: https://test.pypi.org/p/python-lzo + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v6 + with: + path: dist + - run: | + mv dist/*/*.whl dist/ 2>/dev/null || true + find dist -mindepth 1 -type d -delete + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 5588547..b3303ac 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -1,4 +1,4 @@ -name: Build/release wheels for Windows x64 +name: Build/release wheels for Windows on: workflow_dispatch: @@ -9,59 +9,55 @@ on: do_release: description: 'Creating release from artifacts: type "y" to enable' required: false + publish_to_testpypi: + description: 'Publish wheels to TestPyPI' + type: boolean + default: false + push: + tags: + - v* jobs: - build-w64: - runs-on: - - windows-latest - #x- windows-latest-arm64 + build: + runs-on: ${{ matrix.os }} defaults: run: shell: cmd strategy: + fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] - name: ${{ matrix.python-version }} + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] + os: [windows-latest, windows-latest-arm64] + name: "${{ matrix.os }} py${{ matrix.python-version }}" steps: - name: Checkout repo uses: actions/checkout@v4 with: persist-credentials: false - - name: Run cmake - working-directory: .\lzo-2.10 - run: | - md build - cd build - cmake .. - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 - # with: - # msbuild-architecture: x64 - - name: Build lzo static lib - working-directory: .\lzo-2.10\build - run: msbuild lzo_static_lib.vcxproj -p:Configuration=Release;Platform=x64;OutDir=..\ - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} -# architecture: x64 - name: Build wheel env: LZO_DIR: .\lzo-2.10 run: | python -m pip install -U pip wheel build python -m build - ls -l dist + - name: Smoke-test wheel + run: | + pip install dist\*.whl + python -c "import lzo; d=b'test'*42; assert lzo.decompress(lzo.compress(d))==d; print('OK')" - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: ${{ github.event.repository.name }}-py${{ matrix.python-version }} + name: ${{ github.event.repository.name }}-${{ matrix.os }}-py${{ matrix.python-version }} path: dist\*.whl overwrite: true if-no-files-found: error release: if: ${{ github.event.inputs.do_release == 'y' && github.event.inputs.custom_ref != '' }} - needs: [build-w64] + needs: [build] runs-on: ubuntu-latest permissions: contents: write @@ -90,3 +86,24 @@ jobs: --repo ${GITHUB_REPOSITORY} gh release upload '${{ github.event.inputs.custom_ref}}' --repo ${GITHUB_REPOSITORY} --clobber \ ./artifacts/* + + publish-testpypi: + name: Publish to TestPyPI + needs: [build] + if: inputs.publish_to_testpypi + runs-on: ubuntu-latest + environment: + name: release + url: https://test.pypi.org/p/python-lzo + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v6 + with: + path: dist + - run: | + mv dist/*/*.whl dist/ 2>/dev/null || true + find dist -mindepth 1 -type d -delete + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml deleted file mode 100644 index 6848ac6..0000000 --- a/.github/workflows/wheels.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: Build and test wheels - -on: - workflow_dispatch: - push: - tags: - - v* - -jobs: - wheels: - name: Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-20.04, windows-2019, macos-12] - arch: ["x86_64", "arm64"] - 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" - - os: windows-2019 - arch: "arm64" - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - 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@v2.16.2 - env: - CIBW_BUILD: "*${{ matrix.arch }}" - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: ${{ runner.os }}-${{ matrix.arch }} - path: wheelhouse/*.whl - if-no-files-found: error - - sdist: - name: Build sdist - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v4 - with: - # Build sdist on lowest supported Python. - # 3.8 is used because 3.6 has issues with pyproject.toml - # and 3.7 has bpo-41316. - python-version: '3.8' - - name: Build sdist - run: | - python -m pip install -U pip - python -m pip install -U build - python -m build -s - - name: Test sdist - run : python -m pip install dist/*.gz - - name: Upload sdist - uses: actions/upload-artifact@v4 - with: - name: sdist - path: dist/* - if-no-files-found: error - - publish: - name: Publish builds on PyPI - runs-on: ubuntu-latest - needs: [sdist, wheels] - if: ${{ always() && (needs.sdist.result == 'success' || needs.wheels.result == 'success') }} - environment: - name: release - url: https://test.pypi.org/p/python-lzo - permissions: - id-token: write - steps: - - name: Download builds - uses: actions/download-artifact@v4.1.7 - with: - path: dist - - name: Organise - working-directory: dist - run: | - mv **/*.whl . - mv **/*.gz . - find . -type d -delete - - name: Display structure of downloaded files - run: ls -R - - name: Publish package distributions to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - print-hash: true - repository-url: https://test.pypi.org/legacy/ diff --git a/setup.py b/setup.py index 14f57eb..c1b1595 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,10 @@ from __future__ import print_function import os +import shutil import subprocess import sys +import tempfile from glob import glob from setuptools import Command, Extension, setup @@ -26,10 +28,37 @@ def run(self): "pytest"])) +def has_system_lzo2(): + """Return True if liblzo2 can be compiled and linked against.""" + if sys.platform == "win32": + return False + test_c = """ + #include + int main(void) { return lzo_init() == LZO_E_OK ? 0 : 1; } + """ + tmpdir = tempfile.mkdtemp() + try: + src = os.path.join(tmpdir, "test.c") + out = os.path.join(tmpdir, "test") + with open(src, "w") as f: + f.write(test_c) + cc = os.environ.get("CC", "cc") + result = subprocess.run( + [cc, "-o", out, src, "-llzo2"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + return result.returncode == 0 + finally: + shutil.rmtree(tmpdir) + + lzo_dir = os.environ.get("LZO_DIR", "lzo-2.10") # Relative path. +_use_system_lzo = has_system_lzo2() + src_list = ["lzomodule.c"] -if sys.platform == "win32": +if not _use_system_lzo: src_list += glob(os.path.join(lzo_dir, "src/*.c")) setup( @@ -41,7 +70,7 @@ def run(self): name="lzo", sources=src_list, include_dirs=[os.path.join(lzo_dir, "include")], - libraries=['lzo2'] if not sys.platform == "win32" else [], + libraries=['lzo2'] if _use_system_lzo else [], library_dirs=[os.path.join(lzo_dir, "lib")], #extra_link_args=["-flat_namespace"] if sys.platform == "darwin" else [], )