Skip to content

Commit d4477c4

Browse files
Merge pull request #5 from laggykiller/main
Auto build binary wheels with CMake
2 parents 85db6bd + 10dbd88 commit d4477c4

File tree

349 files changed

+592
-66535
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+592
-66535
lines changed

.github/workflows/build.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Build and upload to PyPI
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
# push:
8+
9+
jobs:
10+
build_sdist:
11+
name: Build source distribution
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
submodules: recursive
17+
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.11
21+
22+
- name: Build sdist
23+
run: pipx run build --sdist
24+
25+
- name: Test sdist
26+
run: |
27+
python -m pip install dist/pyrlottie-*.tar.gz
28+
pip install pytest imgcompare
29+
pytest
30+
31+
- uses: actions/upload-artifact@v4
32+
with:
33+
name: artifact-sdist
34+
path: dist/*.tar.gz
35+
36+
build_wheels:
37+
name: Build wheels on ${{ matrix.os }} ${{ matrix.arch }}
38+
runs-on: ${{ matrix.os }}
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
include:
43+
- os: windows-2019
44+
arch: x64
45+
cibw_archs_windows: AMD64
46+
cibw_build: "cp38* pp*"
47+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86_64
48+
- os: windows-2019
49+
arch: x86
50+
cibw_archs_windows: x86
51+
cibw_build: "cp38*"
52+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86
53+
- os: windows-2019
54+
arch: arm64
55+
cibw_archs_windows: ARM64
56+
cibw_build: "cp39*"
57+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=armv8
58+
- os: macos-12
59+
arch: x64
60+
cibw_archs_macos: x86_64
61+
cibw_build: "cp38* pp*"
62+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86_64
63+
- os: macos-14
64+
arch: arm64
65+
cibw_archs_macos: arm64
66+
cibw_build: "cp38* pp*"
67+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=armv8
68+
- os: ubuntu-20.04
69+
arch: x64
70+
cibw_archs_linux: x86_64
71+
cibw_build: "cp38* pp*"
72+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86_64
73+
- os: ubuntu-20.04
74+
arch: x86
75+
cibw_archs_linux: i686
76+
cibw_build: "cp38* pp*"
77+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=x86
78+
- os: ubuntu-20.04
79+
arch: arm64
80+
cibw_archs_linux: aarch64
81+
cibw_build: "cp38* pp*"
82+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=armv8
83+
- os: ubuntu-20.04
84+
arch: ppc64le
85+
cibw_archs_linux: ppc64le
86+
cibw_build: "cp38*"
87+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=ppc64le
88+
- os: ubuntu-20.04
89+
arch: s390x
90+
cibw_archs_linux: s390x
91+
cibw_build: "cp38*"
92+
cibw_environment: PYRLOTTIE_COMPILE_TARGET=s390x
93+
94+
steps:
95+
- uses: actions/setup-python@v5
96+
with:
97+
python-version: 3.11
98+
99+
- name: Install python packages
100+
run: pip install abi3audit patch
101+
102+
- uses: actions/checkout@v4
103+
with:
104+
submodules: recursive
105+
106+
- name: Set up QEMU
107+
if: runner.os == 'Linux'
108+
uses: docker/setup-qemu-action@v2
109+
with:
110+
platforms: all
111+
112+
- name: Build wheels
113+
uses: pypa/[email protected]
114+
env:
115+
CIBW_BUILD_FRONTEND: build
116+
CIBW_ARCHS_WINDOWS: ${{ matrix.cibw_archs_windows }}
117+
CIBW_ARCHS_MACOS: ${{ matrix.cibw_archs_macos }}
118+
CIBW_ARCHS_LINUX: ${{ matrix.cibw_archs_linux }}
119+
CIBW_ENVIRONMENT: ${{ matrix.cibw_environment }}
120+
CIBW_BUILD: ${{ matrix.cibw_build }}
121+
CIBW_TEST_REQUIRES: pytest imgcompare
122+
CIBW_BEFORE_TEST: pip install --only-binary ":all:" Pillow numpy; true
123+
CIBW_BEFORE_TEST_WINDOWS: pip install --only-binary ":all:" Pillow numpy || VER>NUL
124+
CIBW_TEST_COMMAND: pytest {package}/tests
125+
CIBW_TEST_SKIP: "pp* *-*linux_{ppc64le,s390x} *-musllinux_i686"
126+
127+
- name: abi3audit
128+
run: abi3audit $(ls ./wheelhouse/*.whl) --debug --verbose
129+
130+
- uses: actions/upload-artifact@v4
131+
with:
132+
name: artifact-${{ matrix.os }}-${{ matrix.arch }}
133+
path: ./wheelhouse/*.whl
134+
135+
upload_pypi:
136+
needs: [build_wheels, build_sdist]
137+
runs-on: ubuntu-latest
138+
if: github.event_name == 'release' && github.event.action == 'published'
139+
steps:
140+
- uses: actions/download-artifact@v4
141+
with:
142+
# unpacks default artifact into dist/
143+
# if `name: artifact` is omitted, the action will create extra parent dir
144+
pattern: artifact-*
145+
path: dist
146+
147+
- uses: pypa/[email protected]
148+
with:
149+
user: __token__
150+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,9 @@ dmypy.json
163163

164164
# pytype static type analyzer
165165
.pytype/
166+
167+
# CMake
168+
CMakeUserPresets.json
169+
170+
# Conan
171+
conan_output/*

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "libwebp"]
2+
path = libwebp
3+
url = https://github.com/webmproject/libwebp.git
4+
[submodule "rlottie"]
5+
path = rlottie
6+
url = https://github.com/Samsung/rlottie.git

CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
cmake_policy(SET CMP0074 NEW)
3+
4+
find_package(PythonInterp 3 REQUIRED)
5+
6+
set(GET_ARCH_CMD ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/get_arch.py")
7+
set(GET_DEPS_CMD ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/get_deps.py")
8+
set(APPLY_PATCHES_CMD ${PYTHON_EXECUTABLE} "-m" "patch")
9+
10+
message(STATUS "Executing get_arch.py")
11+
execute_process(
12+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13+
COMMAND ${GET_ARCH_CMD}
14+
OUTPUT_VARIABLE PYRLOTTIE_COMPILE_TARGET
15+
)
16+
message(STATUS "Finished get_arch.py")
17+
message(STATUS "PYRLOTTIE_COMPILE_TARGET is ${PYRLOTTIE_COMPILE_TARGET}")
18+
19+
message(STATUS "Executing get_deps.py")
20+
execute_process(
21+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
22+
COMMAND ${GET_DEPS_CMD}
23+
)
24+
message(STATUS "Finished get_deps.py")
25+
26+
file(GLOB PATCH_FILES "${CMAKE_SOURCE_DIR}/patches/*.patch")
27+
foreach(PATCH_FILE ${PATCH_FILES})
28+
message(STATUS "Applying patch ${PATCH_FILE}")
29+
execute_process(
30+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
31+
COMMAND ${APPLY_PATCHES_CMD} ${PATCH_FILE}
32+
COMMAND_ERROR_IS_FATAL ANY
33+
)
34+
message(STATUS "Finished applying patch ${PATCH_FILE}")
35+
endforeach()
36+
37+
if (MSVC)
38+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
39+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
40+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
41+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Zi /Ob0 /Od /RTC1")
42+
elseif (LINUX)
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
44+
elseif (APPLE)
45+
if("${PYRLOTTIE_COMPILE_TARGET}" STREQUAL "armv8")
46+
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
47+
else()
48+
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
49+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
50+
endif()
51+
endif()
52+
53+
set(BUILD_SHARED_LIBS OFF)
54+
set(ZLIB_USE_STATIC_LIBS ON)
55+
set(PNG_USE_STATIC_LIBS ON)
56+
57+
# Add conan packages
58+
set(CONAN_ROOT ${CMAKE_SOURCE_DIR}/conan_output/${PYRLOTTIE_COMPILE_TARGET})
59+
set(CONAN_TOOLCHAIN "${CONAN_ROOT}/conan_toolchain.cmake")
60+
61+
if (EXISTS ${CONAN_TOOLCHAIN})
62+
include(${CONAN_TOOLCHAIN})
63+
else()
64+
message(FATAL_ERROR "The conan_toolchain file could not be found: ${CONAN_TOOLCHAIN}")
65+
endif()
66+
67+
project(pyrlottie)
68+
69+
add_subdirectory(libwebp)
70+
add_subdirectory(rlottie)
71+
72+
# Install the module
73+
install(TARGETS lottie2gif gif2webp
74+
EXCLUDE_FROM_ALL
75+
RUNTIME DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME}
76+
COMPONENT python_module)

README.md

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,19 @@ where to look for certain things:
123123
may have.
124124
-->
125125

126-
## Supported Environments (64bit)
127-
128-
| Environment | Supported |
129-
| ------------- | --------- |
130-
| linux_x86_64 ||
131-
| linux_aarch64 ||
132-
| windows_amd64 ||
133-
| darwin_x86_64 ||
134-
| darwin_arm64 ||
135-
136-
For a full list of machine architecures for Linux see https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
137126

138127
## Install With PIP
139128

140129
```sh
141130
pip install pyrlottie
142131
```
143132

144-
### WSL
145-
146-
Need to preserve execute bits
147-
148-
```sh
149-
mkdir pip-tmp
150-
TMPDIR='./pip-tmp' pip install pyrlottie && rmdir pip-tmp
151-
```
152-
153-
https://github.com/pypa/pip/issues/7666
154-
https://github.com/pypa/pip/issues/6364
155-
156-
Head to https://pypi.org/project/pyrlottie/ for more info
157-
158133
## Language information
159134

160135
### Built for
161136

162-
This program has been written for Python versions 3.8 - 3.11 and has been tested with both 3.8 and
163-
3.11
137+
This program has been written for Python versions 3.8 - 3.12 and has been tested with
138+
both 3.8 and 3.12
164139

165140
## Install Python on Windows
166141

@@ -222,29 +197,19 @@ version.
222197

223198
## Building
224199

225-
This project uses https://github.com/FHPythonUtils/FHMake to automate most of the building. This
226-
command generates the documentation, updates the requirements.txt and builds the library artefacts
227-
228-
Note the functionality provided by fhmake can be approximated by the following
229-
230200
```sh
231-
handsdown --cleanup -o documentation/reference
232-
poetry export -f requirements.txt --output requirements.txt
233-
poetry export -f requirements.txt --with dev --output requirements_optional.txt
234-
poetry build
201+
pip install build
202+
python -m build .
235203
```
236204

237-
`fhmake audit` can be run to perform additional checks
238-
239205
## Testing
240206

241-
For testing with the version of python used by poetry use
242-
243207
```sh
244-
poetry run pytest
208+
pip install .[dev]
209+
pytest
245210
```
246211

247-
Alternatively use `tox` to run tests over python 3.8 - 3.11
212+
Alternatively use `tox` to run tests over python 3.8 - 3.12
248213

249214
```sh
250215
tox

Vagrantfile_linux.rb

Lines changed: 0 additions & 31 deletions
This file was deleted.

conanfile.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
# type: ignore
3+
import shutil
4+
5+
from conan import ConanFile
6+
from conan.tools.cmake import CMakeDeps, CMakeToolchain
7+
8+
9+
class PyrlottieRecipe(ConanFile):
10+
settings = "os", "compiler", "build_type", "arch"
11+
12+
def requirements(self):
13+
self.requires("giflib/5.2.1")
14+
self.requires("libpng/1.6.43")
15+
self.requires("zlib/1.3.1")
16+
self.requires("libjpeg/9e")
17+
18+
def build_requirements(self):
19+
if not shutil.which("cmake"):
20+
self.tool_requires("cmake/[>=3.27]")
21+
22+
def build(self):
23+
build_type = "Release" # noqa: F841
24+
25+
def generate(self):
26+
tc = CMakeToolchain(self)
27+
cmake = CMakeDeps(self)
28+
tc.generate()
29+
cmake.generate()

0 commit comments

Comments
 (0)