Skip to content

Commit

Permalink
Merge pull request #5 from laggykiller/main
Browse files Browse the repository at this point in the history
Auto build binary wheels with CMake
  • Loading branch information
FredHappyface authored Mar 29, 2024
2 parents 85db6bd + 10dbd88 commit d4477c4
Show file tree
Hide file tree
Showing 349 changed files with 592 additions and 66,535 deletions.
150 changes: 150 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Build and upload to PyPI

on:
release:
types:
- published
# push:

jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Build sdist
run: pipx run build --sdist

- name: Test sdist
run: |
python -m pip install dist/pyrlottie-*.tar.gz
pip install pytest imgcompare
pytest
- uses: actions/upload-artifact@v4
with:
name: artifact-sdist
path: dist/*.tar.gz

build_wheels:
name: Build wheels on ${{ matrix.os }} ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
arch: x64
cibw_archs_windows: AMD64
cibw_build: "cp38* pp*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86_64
- os: windows-2019
arch: x86
cibw_archs_windows: x86
cibw_build: "cp38*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86
- os: windows-2019
arch: arm64
cibw_archs_windows: ARM64
cibw_build: "cp39*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=armv8
- os: macos-12
arch: x64
cibw_archs_macos: x86_64
cibw_build: "cp38* pp*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86_64
- os: macos-14
arch: arm64
cibw_archs_macos: arm64
cibw_build: "cp38* pp*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=armv8
- os: ubuntu-20.04
arch: x64
cibw_archs_linux: x86_64
cibw_build: "cp38* pp*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86_64
- os: ubuntu-20.04
arch: x86
cibw_archs_linux: i686
cibw_build: "cp38* pp*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86
- os: ubuntu-20.04
arch: arm64
cibw_archs_linux: aarch64
cibw_build: "cp38* pp*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=armv8
- os: ubuntu-20.04
arch: ppc64le
cibw_archs_linux: ppc64le
cibw_build: "cp38*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=ppc64le
- os: ubuntu-20.04
arch: s390x
cibw_archs_linux: s390x
cibw_build: "cp38*"
cibw_environment: PYRLOTTIE_COMPILE_TARGET=s390x

steps:
- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install python packages
run: pip install abi3audit patch

- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD_FRONTEND: build
CIBW_ARCHS_WINDOWS: ${{ matrix.cibw_archs_windows }}
CIBW_ARCHS_MACOS: ${{ matrix.cibw_archs_macos }}
CIBW_ARCHS_LINUX: ${{ matrix.cibw_archs_linux }}
CIBW_ENVIRONMENT: ${{ matrix.cibw_environment }}
CIBW_BUILD: ${{ matrix.cibw_build }}
CIBW_TEST_REQUIRES: pytest imgcompare
CIBW_BEFORE_TEST: pip install --only-binary ":all:" Pillow numpy; true
CIBW_BEFORE_TEST_WINDOWS: pip install --only-binary ":all:" Pillow numpy || VER>NUL
CIBW_TEST_COMMAND: pytest {package}/tests
CIBW_TEST_SKIP: "pp* *-*linux_{ppc64le,s390x} *-musllinux_i686"

- name: abi3audit
run: abi3audit $(ls ./wheelhouse/*.whl) --debug --verbose

- uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.os }}-${{ matrix.arch }}
path: ./wheelhouse/*.whl

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
pattern: artifact-*
path: dist

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,9 @@ dmypy.json

# pytype static type analyzer
.pytype/

# CMake
CMakeUserPresets.json

# Conan
conan_output/*
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "libwebp"]
path = libwebp
url = https://github.com/webmproject/libwebp.git
[submodule "rlottie"]
path = rlottie
url = https://github.com/Samsung/rlottie.git
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.17)
cmake_policy(SET CMP0074 NEW)

find_package(PythonInterp 3 REQUIRED)

set(GET_ARCH_CMD ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/get_arch.py")
set(GET_DEPS_CMD ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/get_deps.py")
set(APPLY_PATCHES_CMD ${PYTHON_EXECUTABLE} "-m" "patch")

message(STATUS "Executing get_arch.py")
execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GET_ARCH_CMD}
OUTPUT_VARIABLE PYRLOTTIE_COMPILE_TARGET
)
message(STATUS "Finished get_arch.py")
message(STATUS "PYRLOTTIE_COMPILE_TARGET is ${PYRLOTTIE_COMPILE_TARGET}")

message(STATUS "Executing get_deps.py")
execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${GET_DEPS_CMD}
)
message(STATUS "Finished get_deps.py")

file(GLOB PATCH_FILES "${CMAKE_SOURCE_DIR}/patches/*.patch")
foreach(PATCH_FILE ${PATCH_FILES})
message(STATUS "Applying patch ${PATCH_FILE}")
execute_process(
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${APPLY_PATCHES_CMD} ${PATCH_FILE}
COMMAND_ERROR_IS_FATAL ANY
)
message(STATUS "Finished applying patch ${PATCH_FILE}")
endforeach()

if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Zi /Ob0 /Od /RTC1")
elseif (LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
elseif (APPLE)
if("${PYRLOTTIE_COMPILE_TARGET}" STREQUAL "armv8")
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
endif()
endif()

set(BUILD_SHARED_LIBS OFF)
set(ZLIB_USE_STATIC_LIBS ON)
set(PNG_USE_STATIC_LIBS ON)

# Add conan packages
set(CONAN_ROOT ${CMAKE_SOURCE_DIR}/conan_output/${PYRLOTTIE_COMPILE_TARGET})
set(CONAN_TOOLCHAIN "${CONAN_ROOT}/conan_toolchain.cmake")

if (EXISTS ${CONAN_TOOLCHAIN})
include(${CONAN_TOOLCHAIN})
else()
message(FATAL_ERROR "The conan_toolchain file could not be found: ${CONAN_TOOLCHAIN}")
endif()

project(pyrlottie)

add_subdirectory(libwebp)
add_subdirectory(rlottie)

# Install the module
install(TARGETS lottie2gif gif2webp
EXCLUDE_FROM_ALL
RUNTIME DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME}
COMPONENT python_module)
49 changes: 7 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,19 @@ where to look for certain things:
may have.
-->

## Supported Environments (64bit)

| Environment | Supported |
| ------------- | --------- |
| linux_x86_64 ||
| linux_aarch64 ||
| windows_amd64 ||
| darwin_x86_64 ||
| darwin_arm64 ||

For a full list of machine architecures for Linux see https://stackoverflow.com/questions/45125516/possible-values-for-uname-m

## Install With PIP

```sh
pip install pyrlottie
```

### WSL

Need to preserve execute bits

```sh
mkdir pip-tmp
TMPDIR='./pip-tmp' pip install pyrlottie && rmdir pip-tmp
```

https://github.com/pypa/pip/issues/7666
https://github.com/pypa/pip/issues/6364

Head to https://pypi.org/project/pyrlottie/ for more info

## Language information

### Built for

This program has been written for Python versions 3.8 - 3.11 and has been tested with both 3.8 and
3.11
This program has been written for Python versions 3.8 - 3.12 and has been tested with
both 3.8 and 3.12

## Install Python on Windows

Expand Down Expand Up @@ -222,29 +197,19 @@ version.

## Building

This project uses https://github.com/FHPythonUtils/FHMake to automate most of the building. This
command generates the documentation, updates the requirements.txt and builds the library artefacts

Note the functionality provided by fhmake can be approximated by the following

```sh
handsdown --cleanup -o documentation/reference
poetry export -f requirements.txt --output requirements.txt
poetry export -f requirements.txt --with dev --output requirements_optional.txt
poetry build
pip install build
python -m build .
```

`fhmake audit` can be run to perform additional checks

## Testing

For testing with the version of python used by poetry use

```sh
poetry run pytest
pip install .[dev]
pytest
```

Alternatively use `tox` to run tests over python 3.8 - 3.11
Alternatively use `tox` to run tests over python 3.8 - 3.12

```sh
tox
Expand Down
31 changes: 0 additions & 31 deletions Vagrantfile_linux.rb

This file was deleted.

29 changes: 29 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
# type: ignore
import shutil

from conan import ConanFile
from conan.tools.cmake import CMakeDeps, CMakeToolchain


class PyrlottieRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"

def requirements(self):
self.requires("giflib/5.2.1")
self.requires("libpng/1.6.43")
self.requires("zlib/1.3.1")
self.requires("libjpeg/9e")

def build_requirements(self):
if not shutil.which("cmake"):
self.tool_requires("cmake/[>=3.27]")

def build(self):
build_type = "Release" # noqa: F841

def generate(self):
tc = CMakeToolchain(self)
cmake = CMakeDeps(self)
tc.generate()
cmake.generate()
Loading

0 comments on commit d4477c4

Please sign in to comment.