Skip to content

Commit 3c3c2b3

Browse files
authored
Use scikit-build-core instead of setuptools, supports python 3.12, 3.13, drop python 3.6 (#17)
* update linux * fix * fix * update * remove * update headers * update flake8 * move * update * fix * fix * fix me * update github actions * init pyi * update * fix * fix * ready * fix * fix * fix * fix
1 parent 4d8660b commit 3c3c2b3

File tree

20 files changed

+480
-270
lines changed

20 files changed

+480
-270
lines changed

.github/workflows/format.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jobs:
1515
name: Format
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
1921
- uses: actions/setup-python@v4
2022
with:
2123
python-version: "3.x"

.github/workflows/pip.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pip
1+
name: "Pip"
22

33
on:
44
workflow_dispatch:
@@ -9,25 +9,23 @@ on:
99

1010
jobs:
1111
build:
12+
name: Build with Pip
13+
runs-on: ${{ matrix.platform }}
1214
strategy:
1315
fail-fast: false
1416
matrix:
15-
platform: [ubuntu-20.04, windows-2019, macos-11]
16-
python-version: ["3.8", "3.9", "3.10"]
17-
18-
runs-on: ${{ matrix.platform }}
17+
platform: [windows-latest, macos-latest, ubuntu-latest]
18+
python-version: ["3.9", "3.12"]
1919

2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
with:
2323
submodules: true
2424

25-
- uses: actions/setup-python@v4
25+
- uses: actions/setup-python@v5
2626
with:
2727
python-version: ${{ matrix.python-version }}
28-
29-
- name: Add requirements
30-
run: python -m pip install --upgrade wheel setuptools
28+
allow-prereleases: true
3129

3230
- name: Build and install
3331
run: pip install --verbose .[test]

.github/workflows/wheels.yml

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ on:
1010
types:
1111
- published
1212

13+
env:
14+
FORCE_COLOR: 3
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
1320
jobs:
1421
build_sdist:
1522
name: Build SDist
1623
runs-on: ubuntu-latest
1724
steps:
18-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
1926
with:
2027
submodules: true
2128

@@ -25,8 +32,9 @@ jobs:
2532
- name: Check metadata
2633
run: pipx run twine check dist/*
2734

28-
- uses: actions/upload-artifact@v3
35+
- uses: actions/upload-artifact@v4
2936
with:
37+
name: cibw-sdist
3038
path: dist/*.tar.gz
3139

3240

@@ -36,37 +44,29 @@ jobs:
3644
strategy:
3745
fail-fast: false
3846
matrix:
39-
os: [ubuntu-latest, windows-latest, macos-latest]
47+
os: [ubuntu-latest, macos-13, macos-latest, windows-latest]
4048

4149
steps:
42-
- uses: actions/checkout@v3
50+
- uses: actions/checkout@v4
4351
with:
4452
submodules: true
4553

46-
- name: Set up QEMU
47-
if: runner.os == 'Linux'
48-
uses: docker/setup-qemu-action@v2
49-
with:
50-
platforms: all
54+
- uses: astral-sh/setup-uv@v4
5155

52-
- uses: pypa/cibuildwheel@v2.12.0
56+
- uses: pypa/cibuildwheel@v2.22
5357
env:
54-
# CIBW_ARCHS: auto64
55-
CIBW_ARCHS_LINUX: x86_64 aarch64
56-
CIBW_ARCHS_WINDOWS: AMD64 # ARM64
57-
CIBW_ARCHS_MACOS: x86_64 arm64
58-
CIBW_BEFORE_BUILD: pip install numpy --prefer-binary
59-
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
60-
CIBW_SKIP: pp* *i686 *musllinux*
58+
CIBW_ENABLE: cpython-prerelease
59+
CIBW_ARCHS_WINDOWS: auto ARM64
60+
CIBW_SKIP: pp* *i686
6161
CIBW_TEST_SKIP: "*macosx* *win* *aarch64"
6262

6363
- name: Verify clean directory
6464
run: git diff --exit-code
6565
shell: bash
6666

67-
- name: Upload wheels
68-
uses: actions/upload-artifact@v3
67+
- uses: actions/upload-artifact@v4
6968
with:
69+
name: cibw-wheels-${{ matrix.os }}
7070
path: wheelhouse/*.whl
7171

7272

@@ -75,17 +75,28 @@ jobs:
7575
needs: [build_wheels, build_sdist]
7676
runs-on: ubuntu-latest
7777
if: github.event_name == 'release' && github.event.action == 'published'
78+
environment: pypi
79+
permissions:
80+
id-token: write
81+
attestations: write
7882

7983
steps:
80-
- uses: actions/setup-python@v4
84+
- uses: actions/setup-python@v5
8185
with:
8286
python-version: "3.x"
8387

84-
- uses: actions/download-artifact@v3
88+
- uses: actions/download-artifact@v4
8589
with:
86-
name: artifact
90+
pattern: cibw-*
91+
merge-multiple: true
8792
path: dist
8893

89-
- uses: pypa/[email protected]
94+
- name: Generate artifact attestation for sdist and wheels
95+
uses: actions/attest-build-provenance@v1
96+
with:
97+
subject-path: "dist/*"
98+
99+
- uses: pypa/gh-action-pypi-publish@release/v1
90100
with:
101+
attestations: true
91102
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ _generate/
88
*env*
99
wheelhouse
1010
!test.py
11+
pybind-jsoncons

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[submodule "pybind11"]
2-
path = pybind11
3-
url = https://github.com/pybind/pybind11.git
4-
branch = master
51
[submodule "headers"]
62
path = headers
73
url = https://github.com/cubao/headers.git

.pre-commit-config.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ ci:
1616
autoupdate_commit_msg: "chore: update pre-commit hooks"
1717
autofix_commit_msg: "style: pre-commit fixes"
1818

19+
exclude: |
20+
(?x)^(
21+
src/include/.*
22+
)$
23+
24+
1925
repos:
2026
# Standard hooks
2127
- repo: https://github.com/pre-commit/pre-commit-hooks
22-
rev: v4.1.0
28+
rev: v5.0.0
2329
hooks:
2430
- id: check-added-large-files
2531
- id: check-case-conflict
@@ -56,13 +62,13 @@ repos:
5662

5763
# Changes tabs to spaces
5864
- repo: https://github.com/Lucas-C/pre-commit-hooks
59-
rev: v1.1.13
65+
rev: v1.5.5
6066
hooks:
6167
- id: remove-tabs
6268
exclude: ^(docs|Makefile)
6369

6470
- repo: https://github.com/PyCQA/flake8
65-
rev: 3.9.2
71+
rev: 7.2.0
6672
hooks:
6773
- id: flake8
6874
additional_dependencies: [flake8-bugbear]

CMakeLists.txt

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
cmake_minimum_required(VERSION 3.4...3.18)
2-
project(pybind11_rdp)
3-
4-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1+
# Require CMake 3.15+ (matching scikit-build-core) Use new versions of all
2+
# policies up to CMake 3.27
3+
cmake_minimum_required(VERSION 3.15...3.27)
64

5+
# set(CMAKE_BUILD_TYPE "Debug")
76
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
87
set(CMAKE_BUILD_TYPE
98
"Release"
@@ -19,16 +18,38 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
1918
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
2019
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
2120
endif()
21+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pragma-once-outside-header")
23+
endif()
24+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
25+
add_definitions(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}")
26+
add_definitions(-DPROJECT_BINARY_DIR="${PROJECT_BINARY_DIR}")
2227

23-
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/headers/include)
28+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
29+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
30+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
31+
32+
# Scikit-build-core sets these values for you, or you can just hard-code the
33+
# name and version.
34+
project(
35+
${SKBUILD_PROJECT_NAME}
36+
VERSION ${SKBUILD_PROJECT_VERSION}
37+
LANGUAGES CXX)
2438

2539
set(CMAKE_CXX_STANDARD 14)
26-
set(PYBIND11_CPP_STANDARD -std=c++14)
40+
# Find the module development requirements (requires FindPython from 3.17 or
41+
# scikit-build-core's built-in backport)
42+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
43+
find_package(pybind11 CONFIG REQUIRED)
44+
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/headers/include)
45+
46+
# Add a library using FindPython's tooling (pybind11 also provides a helper like
47+
# this)
48+
python_add_library(_core MODULE src/main.cpp WITH_SOABI)
49+
target_link_libraries(_core PRIVATE pybind11::headers)
2750

28-
add_subdirectory(pybind11)
29-
pybind11_add_module(_pybind11_rdp src/main.cpp)
51+
# This is passing in the version as a define just as an example
52+
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
3053

31-
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
32-
# define (VERSION_INFO) here.
33-
target_compile_definitions(_pybind11_rdp
34-
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
54+
# The install directory is the output (wheel) directory
55+
install(TARGETS _core DESTINATION pybind11_rdp)

MANIFEST.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
include README.md LICENSE pybind11/LICENSE
1+
include README.md LICENSE
22
graft headers
3-
graft pybind11/include
4-
graft pybind11/tools
53
graft src
64
graft tests
75
global-include CMakeLists.txt *.cmake

Makefile

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
PROJECT_SOURCE_DIR ?= $(abspath ./)
2+
PROJECT_NAME ?= $(shell basename $(PROJECT_SOURCE_DIR))
3+
NUM_JOBS ?= 8
4+
15
all:
26
@echo nothing special
37

@@ -11,19 +15,23 @@ lint:
1115
pre-commit run -a
1216
lint_install:
1317
pre-commit install
18+
.PHONY: lint
1419

15-
build:
16-
mkdir -p build && cd build && \
17-
cmake .. && make
18-
.PHONY: build
20+
reset_submodules:
21+
git submodule update --init --recursive
22+
23+
pytest:
24+
python3 -m pip install pytest
25+
pytest tests # --capture=tee-sys
26+
.PHONY: test pytest
1927

2028
docs_build:
2129
mkdocs build
2230
docs_serve:
2331
mkdocs serve -a 0.0.0.0:8088
2432

2533
DOCKER_TAG_WINDOWS ?= ghcr.io/cubao/build-env-windows-x64:v0.0.1
26-
DOCKER_TAG_LINUX ?= ghcr.io/cubao/build-env-manylinux2014-x64:v0.0.1
34+
DOCKER_TAG_LINUX ?= ghcr.io/cubao/build-env-manylinux2014-x64:v0.0.4
2735
DOCKER_TAG_MACOS ?= ghcr.io/cubao/build-env-macos-arm64:v0.0.1
2836

2937
test_in_win:
@@ -33,19 +41,29 @@ test_in_mac:
3341
test_in_linux:
3442
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) bash
3543

44+
DEV_CONTAINER_NAME ?= $(USER)_$(subst /,_,$(PROJECT_NAME)____$(PROJECT_SOURCE_DIR))
45+
DEV_CONTAINER_IMAG ?= $(DOCKER_TAG_LINUX)
46+
test_in_dev_container:
47+
docker ps | grep $(DEV_CONTAINER_NAME) \
48+
&& docker exec -it $(DEV_CONTAINER_NAME) bash \
49+
|| docker run --rm --name $(DEV_CONTAINER_NAME) \
50+
--network host --security-opt seccomp=unconfined \
51+
-v `pwd`:`pwd` -w `pwd` -it $(DEV_CONTAINER_IMAG) bash
52+
53+
3654
PYTHON ?= python3
55+
build:
56+
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec pybind11
57+
CMAKE_BUILD_PARALLEL_LEVEL=$(NUM_JOBS) $(PYTHON) -m pip install --no-build-isolation -Ceditable.rebuild=true -Cbuild-dir=build -ve.
3758
python_install:
38-
$(PYTHON) setup.py install --force
39-
python_build:
40-
$(PYTHON) setup.py bdist_wheel
59+
$(PYTHON) -m pip install . --verbose
60+
python_wheel:
61+
$(PYTHON) -m pip wheel . -w build --verbose
4162
python_sdist:
42-
$(PYTHON) setup.py sdist
43-
# tar -tvf dist/pybind11_rdp-*.tar.gz
44-
python_test:
45-
$(PYTHON) -m pip install pytest rdp
46-
$(PYTHON) -c 'from pybind11_rdp import rdp; print(rdp([[1, 1], [2, 2], [3, 3], [4, 4]]))'
47-
pytest tests
48-
$(PYTHON) test.py
63+
$(PYTHON) -m pip install build
64+
$(PYTHON) -m build --sdist --verbose
65+
python_test: pytest
66+
.PHONY: build
4967

5068
# conda create -y -n py36 python=3.6
5169
# conda create -y -n py37 python=3.7
@@ -65,23 +83,24 @@ python_build_py310:
6583
PYTHON=python conda run --no-capture-output -n py310 make python_build
6684
python_build_all: python_build_py36 python_build_py37 python_build_py38 python_build_py39 python_build_py310
6785
python_build_all_in_linux:
68-
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/win:`pwd`/build -it $(DOCKER_TAG_LINUX) make python_build_all
86+
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) make python_build_all
6987
make repair_wheels && rm -rf dist/*.whl && mv wheelhouse/*.whl dist && rm -rf wheelhouse
7088
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310
7189
python_build_all_in_windows: python_build_all
7290

7391
repair_wheels:
7492
python -m pip install auditwheel # sudo apt install patchelf
75-
ls dist/* | xargs -n1 auditwheel repair --plat manylinux2014_x86_64
93+
ls dist/*-linux_x86_64.whl | xargs -n1 auditwheel repair --plat manylinux2014_x86_64
94+
rm -rf dist/*-linux_x86_64.whl && cp wheelhouse/*.whl dist && rm -rf wheelhouse
7695

7796
pypi_remote ?= pypi
7897
upload_wheels:
7998
python -m pip install twine
8099
twine upload dist/*.whl -r $(pypi_remote)
81100

82101
tar.gz:
83-
tar -cvz --exclude .git -f ../pybind11-rdp.tar.gz .
84-
ls -alh ../pybind11-rdp.tar.gz
102+
tar -cvz --exclude .git -f ../$(PROJECT_NAME).tar.gz .
103+
ls -alh ../$(PROJECT_NAME).tar.gz
85104

86105
# https://stackoverflow.com/a/25817631
87106
echo-% : ; @echo -n $($*)

0 commit comments

Comments
 (0)