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

Adapt to nanobind 2.0.0, stubgen with nanobind, multiple improvements #7

Merged
merged 106 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
fd6e35f
WIP: Generate stub with nanobind
laggykiller Feb 17, 2024
aa81801
Auto stub generation
github-actions[bot] Feb 17, 2024
d8a23ff
WIP: Generate stub with nanobind
laggykiller Feb 17, 2024
65f3fb9
WIP: Generate stub with nanobind
laggykiller Feb 17, 2024
3903c20
WIP: Generate stub with nanobind
laggykiller Feb 17, 2024
ae66338
WIP: Generate stub with nanobind
laggykiller Feb 17, 2024
c8d4f89
formatting with ruff
laggykiller Feb 17, 2024
ca7ae85
WIP: Generate stub with nanobind
laggykiller Feb 18, 2024
11787ad
WIP: Generate stub with nanobind
laggykiller Feb 18, 2024
0a3d5e0
Fix docstrings
laggykiller Feb 18, 2024
47e6d17
WIP: commit check and stub generation to repo
laggykiller Feb 18, 2024
5d9407d
WIP: Fix commit check
laggykiller Feb 18, 2024
516e3a5
WIP: Fix commit check
laggykiller Feb 18, 2024
d550137
WIP: Only run commit check on latest commit
laggykiller Feb 18, 2024
076e7b8
Update stub and formatting
github-actions[bot] Feb 18, 2024
572237a
Fix commit action
laggykiller Feb 18, 2024
4ddaa93
Rename action
laggykiller Feb 18, 2024
4be9b2c
Update stub and formatting
github-actions[bot] Feb 18, 2024
cd53506
- Only build required boost components
laggykiller Feb 18, 2024
44ecbb6
Update stub and formatting
github-actions[bot] Feb 18, 2024
b9a068c
Formatting
laggykiller Feb 18, 2024
cfd801b
- Cleaning docstring
laggykiller Feb 18, 2024
473d466
Update stub and formatting
github-actions[bot] Feb 18, 2024
436746c
1.3.0
laggykiller Feb 18, 2024
1b36e90
Test building wheels for all platform
laggykiller Feb 18, 2024
a8240da
Reverse disabling upload_pypi
laggykiller Feb 18, 2024
9eab726
Fix stub typing
laggykiller Feb 19, 2024
a022b80
Update stub and formatting
github-actions[bot] Feb 19, 2024
282375b
Add lipo-dir-merge in source distribution
laggykiller Feb 23, 2024
e33dbcb
Using master branch of nanobind
laggykiller Feb 23, 2024
8f6e2c4
Update stub and formatting
github-actions[bot] Feb 23, 2024
78092b8
Fix is_skip_first binded to incorrect function in binder
laggykiller Feb 27, 2024
596432e
Safer check for non-rgb frame given to add_frame_from_numpy
laggykiller Feb 27, 2024
0330337
fix apngasm_listener typo in binder
laggykiller Feb 27, 2024
46697c0
Add tests
laggykiller Feb 27, 2024
ce93883
Merge branch 'stubgen-official' of https://github.com/laggykiller/apn…
laggykiller Feb 27, 2024
c192276
Run pytest during check_and_fix
laggykiller Feb 27, 2024
c0ee3a7
Test build
laggykiller Feb 27, 2024
9158cd9
Fix build
laggykiller Feb 27, 2024
b077ef2
Add test for with statement
laggykiller Feb 27, 2024
3b7f510
Change macOS version for runner
laggykiller Feb 27, 2024
c046caa
Use last good nanobind for build testing
laggykiller Feb 27, 2024
22274a2
Try building with py-build-cmake==0.2.0.a12
laggykiller Feb 27, 2024
5266a90
use macos-12 and disable s390x as apngasm not working there
laggykiller Feb 27, 2024
5d47d3d
Skip testing on universal2
laggykiller Feb 27, 2024
7f6e949
Fix repeated function name in test
laggykiller Feb 27, 2024
b47196d
Enable pyright in check_and_fix
laggykiller Feb 27, 2024
2f96dbc
Install pillow and numpy during check_and_fix
laggykiller Feb 27, 2024
033c913
Invoke pyright after installing in check_and_fix
laggykiller Feb 27, 2024
0194e6f
Fix check_and_fix
laggykiller Feb 27, 2024
e05abc7
Use nanobind master branch again
laggykiller Feb 27, 2024
e0c878e
Do not specify generator
laggykiller Feb 28, 2024
677aaec
Run conan again for each build; Build with newer macOS runner
laggykiller Feb 28, 2024
3dd21f5
use latest cibuildwheel
laggykiller Feb 28, 2024
5558780
use latest cibuildwheel
laggykiller Feb 28, 2024
a371dd2
Change deployment target for universal2 wheel
laggykiller Feb 28, 2024
cccf996
Fix build
laggykiller Feb 28, 2024
a26537d
Fix universal2 build
laggykiller Feb 28, 2024
751e988
Update stub and formatting
github-actions[bot] Feb 28, 2024
281c262
Fix universal2 build
laggykiller Feb 28, 2024
7458bac
Update stub and formatting
github-actions[bot] Feb 28, 2024
43fdd45
Fix universal2 build
laggykiller Feb 28, 2024
5ded6f1
Merge branch 'stubgen-official' of https://github.com/laggykiller/apn…
laggykiller Feb 28, 2024
95b9a81
Clean conan_output before build
laggykiller Feb 28, 2024
4c072d9
Patching conan toolchain for universal2
laggykiller Feb 28, 2024
c6636d4
Update stub and formatting
github-actions[bot] Feb 28, 2024
994846e
Also format example and tests
laggykiller Feb 28, 2024
54eb1ef
Linting
laggykiller Feb 28, 2024
885495f
Fix build
laggykiller Feb 28, 2024
485e9e5
Remove conan_output rmtree as not necessary
laggykiller Feb 28, 2024
075bccb
Build with macos deployment target 10.9
laggykiller Feb 28, 2024
f15f5cc
Also install boost filesystem
laggykiller Feb 28, 2024
249f430
Also install boost atomic as dep of filesystem
laggykiller Feb 28, 2024
5f09ff1
Update apngasm submodule
laggykiller Feb 28, 2024
9205c1d
Fix test
laggykiller Feb 28, 2024
0de1e19
Do not set extra flags and deployment target for macos
laggykiller Feb 28, 2024
e6b0ff5
Compile with `-fno-aligned-allocation`
laggykiller Feb 28, 2024
dc27459
switch back to osx10.9-compat branch of apngasm
laggykiller Feb 28, 2024
236034e
Fix tmpdir typing in tests
laggykiller Mar 1, 2024
34e288d
Fix compiling on cygwin
laggykiller Mar 1, 2024
fa1c57a
Update stub and formatting
github-actions[bot] Mar 1, 2024
451feb5
Simplify declspec logic
laggykiller Mar 1, 2024
e0a1710
Improve ease of building on cygwin, mingw and msys
laggykiller Mar 1, 2024
9dfacb5
Merge branch 'stubgen-official' of https://github.com/laggykiller/apn…
laggykiller Mar 1, 2024
299c1a9
Only build abi3 wheels for minimum supported cpython version
laggykiller Mar 1, 2024
8dffcde
Set abi3_minimum_cpython_version back to 312; Run abi3audit
laggykiller Mar 1, 2024
f2f5e07
Fix abi3audit command in build.yml
laggykiller Mar 1, 2024
276c8b4
Use python 3.11 in github action
laggykiller Mar 1, 2024
38c1a48
More robust abi3audit github action command
laggykiller Mar 1, 2024
30da52d
Fix abi3audit github action step
laggykiller Mar 1, 2024
a3c29d4
Fix for latest nanobind
laggykiller Mar 9, 2024
d64ffa8
Move linting and formatting tools settings to pyproject.toml
laggykiller Mar 9, 2024
91011d6
Specify directories to check for mypy
laggykiller Mar 9, 2024
d0c62ea
Fix mypy config
laggykiller Mar 9, 2024
7c99e88
Install isort in github action
laggykiller Mar 9, 2024
990d744
Update stub and formatting
github-actions[bot] Mar 9, 2024
9342fa2
Update project description
laggykiller Mar 9, 2024
1b9b5f7
Update cibuildwheel
laggykiller Mar 12, 2024
44a010f
Add optional dependencies
laggykiller Mar 21, 2024
4f2ae2e
Fix check_and_fix; Improve readme
laggykiller Mar 21, 2024
5c9a14c
check_and_fix typo
laggykiller Mar 21, 2024
9788231
Update stub and formatting
github-actions[bot] Mar 21, 2024
7ecfe39
Fix build
laggykiller Mar 21, 2024
d862e6b
getting path of cygcheck is unreliable way to determine if inside cygwin
laggykiller Mar 24, 2024
e522995
Update nanobind to latest release
laggykiller May 23, 2024
0d65551
Adapt to new nanobind 2.0.0 ndarray constructor signature
laggykiller May 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 71 additions & 55 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
release:
types:
- [published]
release:
types:
- published

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

- uses: actions/setup-python@v4
with:
python-version: 3.8

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

- name: Test sdist
run: |
python -m pip install dist/apngasm_python-*.tar.gz
pip install pytest numpy Pillow
pytest

- uses: actions/upload-artifact@v3
with:
path: dist/apngasm_python-*.tar.gz

build_wheels:
name: Build wheels for ${{ matrix.os }} ${{ matrix.cibw_archs }} ${{ matrix.cibw_build }}
runs-on: ${{ matrix.os }}
Expand All @@ -18,71 +43,66 @@ jobs:
include:
- os: windows-2019
cibw_archs: AMD64
cibw_build: "*"
cibw_build: "cp38* pp*"
cibw_environment: APNGASM_COMPILE_TARGET=x86_64
- os: windows-2019
cibw_archs: x86
cibw_build: "*"
cibw_build: "cp38*"
cibw_environment: APNGASM_COMPILE_TARGET=x86
- os: windows-2019
cibw_archs: ARM64
cibw_build: "*"
cibw_build: "cp39*"
cibw_environment: APNGASM_COMPILE_TARGET=armv8
- os: macos-11
- os: macos-12
cibw_archs: x86_64
cibw_build: "*"
cibw_environment: >
APNGASM_COMPILE_TARGET=x86_64
_PYTHON_HOST_PLATFORM=macosx-10.15-x86_64
MACOSX_DEPLOYMENT_TARGET=10.15
- os: macos-11
cibw_build: "cp38* pp*"
cibw_environment: APNGASM_COMPILE_TARGET=x86_64
- os: macos-14
cibw_archs: arm64
cibw_build: "*"
cibw_environment: >
APNGASM_COMPILE_TARGET=armv8
_PYTHON_HOST_PLATFORM=macosx-11.0-arm64
MACOSX_DEPLOYMENT_TARGET=11.0
- os: macos-11
cibw_build: "cp38* pp*"
cibw_environment: APNGASM_COMPILE_TARGET=armv8
- os: macos-14
cibw_archs: universal2
cibw_build: "*"
cibw_environment: >
APNGASM_COMPILE_TARGET=universal2
_PYTHON_HOST_PLATFORM=macosx-11.0-universal2
MACOSX_DEPLOYMENT_TARGET=11.0
cibw_build: "cp38* pp*"
cibw_environment: APNGASM_COMPILE_TARGET=universal2
- os: ubuntu-20.04
cibw_archs: x86_64
cibw_build: "*"
cibw_build: "cp38* pp*"
cibw_environment: APNGASM_COMPILE_TARGET=x86_64
- os: ubuntu-20.04
cibw_archs: i686
cibw_build: "*"
cibw_build: "cp38* pp*"
cibw_environment: APNGASM_COMPILE_TARGET=x86
- os: ubuntu-20.04
cibw_archs: aarch64
cibw_build: "*-musllinux_*"
cibw_build: "cp38*-musllinux_* pp*-musllinux_*"
cibw_environment: APNGASM_COMPILE_TARGET=armv8
- os: ubuntu-20.04
cibw_archs: aarch64
cibw_build: "*-manylinux_*"
cibw_build: "cp38*-manylinux_* pp*-manylinux_*"
cibw_environment: APNGASM_COMPILE_TARGET=armv8
- os: ubuntu-20.04
cibw_archs: ppc64le
cibw_build: "*-musllinux_*"
cibw_build: "cp38*-musllinux_*"
cibw_environment: APNGASM_COMPILE_TARGET=ppc64le
- os: ubuntu-20.04
cibw_archs: ppc64le
cibw_build: "*-manylinux_*"
cibw_build: "cp38*-manylinux_*"
cibw_environment: APNGASM_COMPILE_TARGET=ppc64le
- os: ubuntu-20.04
cibw_archs: s390x
cibw_build: "*-musllinux_*"
cibw_environment: APNGASM_COMPILE_TARGET=s390x
- os: ubuntu-20.04
cibw_archs: s390x
cibw_build: "*-manylinux_*"
cibw_environment: APNGASM_COMPILE_TARGET=s390x
# - os: ubuntu-20.04
# cibw_archs: s390x
# cibw_build: "*-musllinux_*"
# cibw_environment: APNGASM_COMPILE_TARGET=s390x
# - os: ubuntu-20.04
# cibw_archs: s390x
# cibw_build: "*-manylinux_*"
# cibw_environment: APNGASM_COMPILE_TARGET=s390x

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

- uses: actions/checkout@v3
with:
submodules: true
Expand All @@ -94,37 +114,32 @@ jobs:
platforms: all

- name: Build wheels for ${{ matrix.os }} ${{ matrix.cibw_archs }} ${{ matrix.cibw_build }}
uses: pypa/cibuildwheel@v2.16.5
uses: pypa/cibuildwheel@v2.17.0
env:
CIBW_BUILD_FRONTEND: build
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_BEFORE_ALL: ${{ matrix.cibw_before_all }}
# CIBW_ENVIRONMENT: PY_BUILD_CMAKE_VERBOSE=1 ${{ matrix.cibw_environment }}
CIBW_ENVIRONMENT: ${{ matrix.cibw_environment }}
CIBW_BUILD: ${{ matrix.cibw_build }}
CIBW_TEST_REQUIRES: pytest
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*

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

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

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

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

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

# upload_pypi_test:
# needs: [build_wheels, build_sdist]
# runs-on: ubuntu-latest
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
# steps:
# - uses: actions/download-artifact@v3
# with:
Expand All @@ -142,6 +157,7 @@ jobs:
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@v3
with:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/check_and_fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Check, update stub and formatting

on:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check_and_fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
submodules: recursive
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install test
run: pip install .[full,test,lint]
- name: Ruff check
run: ruff check
- name: Ruff format
run: ruff format
- name: mypy
run: mypy
- name: isort
run: isort .
- name: nanobind stubgen
run: |
pip install nanobind
python -m nanobind.stubgen \
-m apngasm_python._apngasm_python \
-o src-python/apngasm_python/_apngasm_python.pyi \
-M src-python/apngasm_python/py.typed
- name: Pytest
run: pytest
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Update stub and formatting
branch: ${{ steps.extract_branch.outputs.branch }}
27 changes: 0 additions & 27 deletions .github/workflows/update_stub.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ dist/
.py-build-cmake_cache/
.vscode/
conan_output/
example/output/
samples/output/
venv/
docs/_build/
CMakeUserPresets.json
42 changes: 22 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,35 @@ execute_process(
)
message(STATUS "Finished get_deps.py")

if (WIN32)
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(${APNGASM_COMPILE_TARGET} STREQUAL "x86_64")
if(${APNGASM_COMPILE_TARGET} STREQUAL "armv8")
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++ -fno-aligned-allocation")
endif()
endif()

set(ZLIB_USE_STATIC_LIBS ON)
set(PNG_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_LIBS ON)
if (WIN32)
if (MSVC)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()

# Add conan packages
if ("${APNGASM_COMPILE_TARGET}" STREQUAL "universal2")
# x86_64 Contians static libraries that are universal2
if ("${APNGASM_COMPILE_TARGET}" STREQUAL "universal2_x86_64")
set(CONAN_TOOLCHAIN ${CMAKE_SOURCE_DIR}/conan_output/x86_64/conan_toolchain.cmake)
elseif ("${APNGASM_COMPILE_TARGET}" STREQUAL "universal2_armv8")
set(CONAN_TOOLCHAIN ${CMAKE_SOURCE_DIR}/conan_output/armv8/conan_toolchain.cmake)
else()
set(CONAN_TOOLCHAIN ${CMAKE_SOURCE_DIR}/conan_output/${APNGASM_COMPILE_TARGET}/conan_toolchain.cmake)
endif()
Expand All @@ -58,7 +61,7 @@ else()
message(FATAL_ERROR "The conan_toolchain file could not be found: ${CONAN_TOOLCHAIN}")
endif()

project(apngasm-python VERSION 1.2.3)
project(apngasm-python VERSION 1.3.0)
set(PY_VERSION_SUFFIX "")
set(PY_FULL_VERSION ${PROJECT_VERSION}${PY_VERSION_SUFFIX})

Expand All @@ -76,7 +79,7 @@ find_nanobind_python_first()

# Compile the Python module
nanobind_add_module(_apngasm_python "src/apngasm_python.cpp" NB_STATIC STABLE_ABI)
if (WIN32)
if (MSVC)
nanobind_compile_options(_apngasm_python "/MT /MP /bigobj")
endif()
target_compile_definitions(_apngasm_python PRIVATE _apngasm_python_EXPORTS)
Expand All @@ -101,7 +104,7 @@ set_target_properties(_apngasm_python PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN true
POSITION_INDEPENDENT_CODE true)
if (WIN32)
if (MSVC)
set_target_properties(_apngasm_python PROPERTIES LINK_FALGS_RELEASE "/WHOLEARCHIVE:MNN")
elseif (LINUX)
target_link_options(_apngasm_python PRIVATE "LINKER:--exclude-libs,ALL")
Expand All @@ -114,14 +117,13 @@ install(TARGETS _apngasm_python
COMPONENT python_modules)

# Generate stubs for the Python module
option(WITH_PY_STUBS
"Generate Python stub files (.pyi) for the Python module." On)
if (WITH_PY_STUBS AND NOT CMAKE_CROSSCOMPILING)
include(cmake/NanobindStubgen.cmake)
nanobind_stubgen(_apngasm_python)
add_custom_command(TARGET _apngasm_python POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} patch_stub.py $<TARGET_FILE_DIR:_apngasm_python>/_apngasm_python.pyi
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/scripts
USES_TERMINAL)
nanobind_stubgen_install(_apngasm_python ${PY_BUILD_CMAKE_MODULE_NAME})
endif()
nanobind_add_stub(
apngasm_python_stub
INSTALL_TIME
MODULE apngasm_python._apngasm_python
OUTPUT "${PY_BUILD_CMAKE_MODULE_NAME}/_apngasm_python.pyi"
MARKER_FILE "${PY_BUILD_CMAKE_MODULE_NAME}/py.typed"
COMPONENT python_modules
EXCLUDE_FROM_ALL
VERBOSE
)
Loading