Skip to content

Commit

Permalink
add typing stubs (#19)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
district10 and zhixiong-tang authored Oct 3, 2024
1 parent 2a5c510 commit a5be206
Show file tree
Hide file tree
Showing 22 changed files with 1,292 additions and 345 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.9"
- uses: pre-commit/action@v3.0.0
4 changes: 2 additions & 2 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-20.04, windows-2019, macos-11]
python-version: ["3.8", "3.9", "3.10"]
platform: [ubuntu-20.04, windows-2019, macos-13]
python-version: ["3.9"]

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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
platforms: all

- uses: pypa/cibuildwheel@v2.12.0
- uses: pypa/cibuildwheel@v2.21.1
env:
# CIBW_ARCHS: auto64
CIBW_ARCHS_LINUX: x86_64 aarch64
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
steps:
- uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.9"

- uses: actions/download-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ _generate/
*env*
wheelhouse
!test.py
stubs
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[submodule "pybind11"]
path = pybind11
url = https://github.com/pybind/pybind11.git
branch = master
[submodule "headers"]
path = headers
url = https://github.com/cubao/headers.git
40 changes: 16 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ci:
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -33,39 +33,31 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace

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

# Sort your imports in a standard form
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
# Checking static types
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.0.1"
hooks:
- id: isort

# Upgrade older Python syntax
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- id: mypy
files: "setup.py"
args: []
additional_dependencies: [types-setuptools]

# Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.13
rev: v1.4.2
hooks:
- id: remove-tabs
exclude: ^(docs|Makefile)

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]

# CMake formatting
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
Expand Down
37 changes: 25 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
cmake_minimum_required(VERSION 3.4...3.18)
project(polyline_ruler)
cmake_minimum_required(VERSION 3.15...3.26)
if(NOT DEFINED SKBUILD_PROJECT_NAME)
set(SKBUILD_PROJECT_NAME "polyline_ruler")
endif()
if(NOT DEFINED PROJECT_VERSION)
set(PROJECT_VERSION "dev")
endif()
# https://scikit-build-core.readthedocs.io/en/latest/cmakelists.html#accessing-information
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)

# set(CMAKE_BUILD_TYPE Debug)

if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE
"Release"
Expand All @@ -22,15 +33,17 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()

include_directories(${PROJECT_SOURCE_DIR}/headers/include)

set(CMAKE_CXX_STANDARD 17)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/headers/include)
set(PYBIND11_CPP_STANDARD -std=c++17)

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

# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
# define (VERSION_INFO) here.
target_compile_definitions(polyline_ruler
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
file(GLOB SRCS src/main.cpp)
python_add_library(_core MODULE ${SRCS} WITH_SOABI)
target_link_libraries(_core PRIVATE pybind11::headers)
target_include_directories(_core PRIVATE src)
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
install(TARGETS _core DESTINATION ${PROJECT_NAME})
44 changes: 22 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ lint:
lint_install:
pre-commit install

build:
mkdir -p build && cd build && \
cmake .. && make
.PHONY: build

docs_build:
mkdocs build
docs_serve:
Expand Down Expand Up @@ -47,28 +42,31 @@ test_in_dev_container:
-v `pwd`:`pwd` -w `pwd` -it $(DEV_CONTAINER_IMAG) bash

PYTHON ?= python3
build:
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec pybind11
CMAKE_BUILD_PARALLEL_LEVEL=$(NUM_JOBS) $(PYTHON) -m pip install --no-build-isolation -Ceditable.rebuild=true -Cbuild-dir=build -ve.
python_install:
$(PYTHON) setup.py install
python_build:
$(PYTHON) setup.py bdist_wheel
$(PYTHON) -m pip install . --verbose
python_wheel:
$(PYTHON) -m pip wheel . -w build --verbose
python_sdist:
$(PYTHON) setup.py sdist
# tar -tvf dist/polyline_ruler-*.tar.gz
python_test:
$(PYTHON) -m pytest tests/test_basic.py --capture tee-sys -vv -x
pytest: python_test
.PHONY: python_install python_build python_sdist python_test
$(PYTHON) -m pip sdist . --verbose
python_test: pytest
pytest:
python3 -m pip install pytest
pytest tests/test_basic.py
.PHONY: build

restub:
pybind11-stubgen polyline_ruler._core -o stubs
cp -rf stubs/polyline_ruler/_core src/polyline_ruler

# conda create -y -n py36 python=3.6
# conda create -y -n py37 python=3.7
# conda create -y -n py38 python=3.8
# conda create -y -n py39 python=3.9
# conda create -y -n py310 python=3.10
# conda create -y -n py311 python=3.11
# conda create -y -n py312 python=3.12
# conda env list
python_build_py36:
PYTHON=python conda run --no-capture-output -n py36 make python_build
python_build_py37:
PYTHON=python conda run --no-capture-output -n py37 make python_build
python_build_py38:
PYTHON=python conda run --no-capture-output -n py38 make python_build
python_build_py39:
Expand All @@ -77,11 +75,13 @@ python_build_py310:
PYTHON=python conda run --no-capture-output -n py310 make python_build
python_build_py311:
PYTHON=python conda run --no-capture-output -n py311 make python_build
python_build_all: python_build_py36 python_build_py37 python_build_py38 python_build_py39 python_build_py310 python_build_py311
python_build_py312:
PYTHON=python conda run --no-capture-output -n py312 make python_build
python_build_all: python_build_py38 python_build_py39 python_build_py310 python_build_py311 python_build_py312
python_build_all_in_linux:
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) make python_build_all
make repair_wheels && rm -rf dist/*.whl && mv wheelhouse/*.whl dist && rm -rf wheelhouse
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310 python_build_py311
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310 python_build_py311 python_build_py312
python_build_all_in_windows: python_build_all

repair_wheels:
Expand Down
2 changes: 1 addition & 1 deletion headers
Submodule headers updated 828 files
1 change: 0 additions & 1 deletion pybind11
Submodule pybind11 deleted from 442261
89 changes: 78 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,92 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"ninja",
"cmake>=3.12",
requires = ["scikit-build-core>=0.3.3", "pybind11"]
build-backend = "scikit_build_core.build"


[project]
name = "polyline_ruler"
version = "0.0.6"
url = "https://polyline-ruler.readthedocs.io"
description="cubao/polyline-ruler is more than mapbox/cheap-ruler"
readme = "README.md"
authors = [
{ name = "district10", email = "dvorak4tzx@gmail.com" },
]
build-backend = "setuptools.build_meta"
requires-python = ">=3.7"
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.optional-dependencies]
test = ["pytest", "scipy"]


[tool.scikit-build]
wheel.expand-macos-universal-tags = true

[tool.isort]
profile = "black"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = ["error"]
log_cli_level = "INFO"
filterwarnings = [
"error",
]
testpaths = ["tests"]


[tool.cibuildwheel]
test-command = "pytest {project}/tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64"]
# Setuptools bug causes collision between pypy and cpython artifacts
before-build = "rm -rf {project}/build"
build-verbosity = 1


[tool.ruff]
src = ["src"]

[tool.ruff.lint]
exclude = ["*.pyi"]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
ignore = [
"PLR09", # Too many X
"PLR2004", # Magic comparison
"PTH100",
"PTH103",
"PTH120",
]
isort.required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20", "PT018", "NPY002"]
Loading

0 comments on commit a5be206

Please sign in to comment.