Skip to content

Commit a5be206

Browse files
add typing stubs (#19)
* update deps * add pybind11 * fix * fix * fix * fix * fix * fix * add stubs * not good * fix * lint * fix * fix * update * fix * fix * fix * update * update header * fix --------- Co-authored-by: tang zhixiong <zhixiong.tang@momenta.ai>
1 parent 2a5c510 commit a5be206

22 files changed

+1292
-345
lines changed

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- uses: actions/setup-python@v4
2020
with:
21-
python-version: "3.x"
21+
python-version: "3.9"
2222
- uses: pre-commit/action@v3.0.0

.github/workflows/pip.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
platform: [ubuntu-20.04, windows-2019, macos-11]
16-
python-version: ["3.8", "3.9", "3.10"]
15+
platform: [ubuntu-20.04, windows-2019, macos-13]
16+
python-version: ["3.9"]
1717

1818
runs-on: ${{ matrix.platform }}
1919

.github/workflows/wheels.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
with:
5050
platforms: all
5151

52-
- uses: pypa/cibuildwheel@v2.12.0
52+
- uses: pypa/cibuildwheel@v2.21.1
5353
env:
5454
# CIBW_ARCHS: auto64
5555
CIBW_ARCHS_LINUX: x86_64 aarch64
@@ -79,7 +79,7 @@ jobs:
7979
steps:
8080
- uses: actions/setup-python@v4
8181
with:
82-
python-version: "3.x"
82+
python-version: "3.9"
8383

8484
- uses: actions/download-artifact@v3
8585
with:

.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+
stubs

.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: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ci:
1919
repos:
2020
# Standard hooks
2121
- repo: https://github.com/pre-commit/pre-commit-hooks
22-
rev: v4.1.0
22+
rev: v4.4.0
2323
hooks:
2424
- id: check-added-large-files
2525
- id: check-case-conflict
@@ -33,39 +33,31 @@ repos:
3333
- id: requirements-txt-fixer
3434
- id: trailing-whitespace
3535

36-
# Black, the code formatter, natively supports pre-commit
37-
- repo: https://github.com/psf/black
38-
rev: 22.3.0
36+
# Check linting and style issues
37+
- repo: https://github.com/astral-sh/ruff-pre-commit
38+
rev: "v0.6.5"
3939
hooks:
40-
- id: black
41-
exclude: ^(docs)
40+
- id: ruff
41+
args: ["--fix", "--show-fixes"]
42+
- id: ruff-format
43+
exclude: ^(docs)
4244

43-
# Sort your imports in a standard form
44-
- repo: https://github.com/PyCQA/isort
45-
rev: 5.11.5
45+
# Checking static types
46+
- repo: https://github.com/pre-commit/mirrors-mypy
47+
rev: "v1.0.1"
4648
hooks:
47-
- id: isort
48-
49-
# Upgrade older Python syntax
50-
- repo: https://github.com/asottile/pyupgrade
51-
rev: v2.31.1
52-
hooks:
53-
- id: pyupgrade
54-
args: ["--py36-plus"]
49+
- id: mypy
50+
files: "setup.py"
51+
args: []
52+
additional_dependencies: [types-setuptools]
5553

5654
# Changes tabs to spaces
5755
- repo: https://github.com/Lucas-C/pre-commit-hooks
58-
rev: v1.1.13
56+
rev: v1.4.2
5957
hooks:
6058
- id: remove-tabs
6159
exclude: ^(docs|Makefile)
6260

63-
- repo: https://github.com/PyCQA/flake8
64-
rev: 3.9.2
65-
hooks:
66-
- id: flake8
67-
additional_dependencies: [flake8-bugbear]
68-
6961
# CMake formatting
7062
- repo: https://github.com/cheshirekow/cmake-format-precommit
7163
rev: v0.6.13

CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
cmake_minimum_required(VERSION 3.4...3.18)
2-
project(polyline_ruler)
1+
cmake_minimum_required(VERSION 3.15...3.26)
2+
if(NOT DEFINED SKBUILD_PROJECT_NAME)
3+
set(SKBUILD_PROJECT_NAME "polyline_ruler")
4+
endif()
5+
if(NOT DEFINED PROJECT_VERSION)
6+
set(PROJECT_VERSION "dev")
7+
endif()
8+
# https://scikit-build-core.readthedocs.io/en/latest/cmakelists.html#accessing-information
9+
project(
10+
${SKBUILD_PROJECT_NAME}
11+
VERSION ${SKBUILD_PROJECT_VERSION}
12+
LANGUAGES CXX)
313

414
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
515
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
16+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
17+
set(CMAKE_CXX_STANDARD 17)
618

719
# set(CMAKE_BUILD_TYPE Debug)
8-
920
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
1021
set(CMAKE_BUILD_TYPE
1122
"Release"
@@ -22,15 +33,17 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
2233
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
2334
endif()
2435

25-
include_directories(${PROJECT_SOURCE_DIR}/headers/include)
26-
27-
set(CMAKE_CXX_STANDARD 17)
36+
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/headers/include)
2837
set(PYBIND11_CPP_STANDARD -std=c++17)
2938

30-
add_subdirectory(pybind11)
31-
pybind11_add_module(polyline_ruler src/main.cpp)
39+
# https://scikit-build-core.readthedocs.io/en/latest/getting_started.html
40+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
41+
find_package(pybind11 CONFIG REQUIRED)
42+
include_directories(headers/include)
3243

33-
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
34-
# define (VERSION_INFO) here.
35-
target_compile_definitions(polyline_ruler
36-
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
44+
file(GLOB SRCS src/main.cpp)
45+
python_add_library(_core MODULE ${SRCS} WITH_SOABI)
46+
target_link_libraries(_core PRIVATE pybind11::headers)
47+
target_include_directories(_core PRIVATE src)
48+
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
49+
install(TARGETS _core DESTINATION ${PROJECT_NAME})

Makefile

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ lint:
1515
lint_install:
1616
pre-commit install
1717

18-
build:
19-
mkdir -p build && cd build && \
20-
cmake .. && make
21-
.PHONY: build
22-
2318
docs_build:
2419
mkdocs build
2520
docs_serve:
@@ -47,28 +42,31 @@ test_in_dev_container:
4742
-v `pwd`:`pwd` -w `pwd` -it $(DEV_CONTAINER_IMAG) bash
4843

4944
PYTHON ?= python3
45+
build:
46+
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec pybind11
47+
CMAKE_BUILD_PARALLEL_LEVEL=$(NUM_JOBS) $(PYTHON) -m pip install --no-build-isolation -Ceditable.rebuild=true -Cbuild-dir=build -ve.
5048
python_install:
51-
$(PYTHON) setup.py install
52-
python_build:
53-
$(PYTHON) setup.py bdist_wheel
49+
$(PYTHON) -m pip install . --verbose
50+
python_wheel:
51+
$(PYTHON) -m pip wheel . -w build --verbose
5452
python_sdist:
55-
$(PYTHON) setup.py sdist
56-
# tar -tvf dist/polyline_ruler-*.tar.gz
57-
python_test:
58-
$(PYTHON) -m pytest tests/test_basic.py --capture tee-sys -vv -x
59-
pytest: python_test
60-
.PHONY: python_install python_build python_sdist python_test
53+
$(PYTHON) -m pip sdist . --verbose
54+
python_test: pytest
55+
pytest:
56+
python3 -m pip install pytest
57+
pytest tests/test_basic.py
58+
.PHONY: build
59+
60+
restub:
61+
pybind11-stubgen polyline_ruler._core -o stubs
62+
cp -rf stubs/polyline_ruler/_core src/polyline_ruler
6163

62-
# conda create -y -n py36 python=3.6
63-
# conda create -y -n py37 python=3.7
6464
# conda create -y -n py38 python=3.8
6565
# conda create -y -n py39 python=3.9
6666
# conda create -y -n py310 python=3.10
67+
# conda create -y -n py311 python=3.11
68+
# conda create -y -n py312 python=3.12
6769
# conda env list
68-
python_build_py36:
69-
PYTHON=python conda run --no-capture-output -n py36 make python_build
70-
python_build_py37:
71-
PYTHON=python conda run --no-capture-output -n py37 make python_build
7270
python_build_py38:
7371
PYTHON=python conda run --no-capture-output -n py38 make python_build
7472
python_build_py39:
@@ -77,11 +75,13 @@ python_build_py310:
7775
PYTHON=python conda run --no-capture-output -n py310 make python_build
7876
python_build_py311:
7977
PYTHON=python conda run --no-capture-output -n py311 make python_build
80-
python_build_all: python_build_py36 python_build_py37 python_build_py38 python_build_py39 python_build_py310 python_build_py311
78+
python_build_py312:
79+
PYTHON=python conda run --no-capture-output -n py312 make python_build
80+
python_build_all: python_build_py38 python_build_py39 python_build_py310 python_build_py311 python_build_py312
8181
python_build_all_in_linux:
8282
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) make python_build_all
8383
make repair_wheels && rm -rf dist/*.whl && mv wheelhouse/*.whl dist && rm -rf wheelhouse
84-
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310 python_build_py311
84+
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310 python_build_py311 python_build_py312
8585
python_build_all_in_windows: python_build_all
8686

8787
repair_wheels:

headers

Submodule headers updated 828 files

pybind11

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)