Skip to content

Commit 2050715

Browse files
add typing stubs (#3)
* remove pybind11 * update * fix * fix * fix * fix * move code * fix * update * fix * fix * fix * fix --------- Co-authored-by: tang zhixiong <[email protected]>
1 parent 55c5c8b commit 2050715

21 files changed

+789
-333
lines changed

.github/workflows/format.yml

+1-1
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/[email protected]

.github/workflows/pip.yml

+2-2
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
with:
4444
submodules: true
4545

46-
- uses: pypa/cibuildwheel@v2.12.0
46+
- uses: pypa/cibuildwheel@v2.21.1
4747
env:
4848
# CIBW_ARCHS: auto64
4949
CIBW_ARCHS_LINUX: x86_64
@@ -73,7 +73,7 @@ jobs:
7373
steps:
7474
- uses: actions/setup-python@v4
7575
with:
76-
python-version: "3.x"
76+
python-version: "3.9"
7777

7878
- uses: actions/download-artifact@v3
7979
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ _generate/
88
*env*
99
wheelhouse
1010
site
11+
stubs

.gitmodules

-4
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

+5-9
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,14 @@ 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: 23.1.0
39-
hooks:
40-
- id: black
41-
exclude: ^(docs)
42-
43-
- repo: https://github.com/charliermarsh/ruff-pre-commit
44-
rev: "v0.0.254"
36+
# Check linting and style issues
37+
- repo: https://github.com/astral-sh/ruff-pre-commit
38+
rev: "v0.6.5"
4539
hooks:
4640
- id: ruff
4741
args: ["--fix", "--show-fixes"]
42+
- id: ruff-format
43+
exclude: ^(docs)
4844

4945
# Checking static types
5046
- repo: https://github.com/pre-commit/mirrors-mypy

.vscode/c_cpp_properties.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"defines": [],
6+
"compilerPath": "/usr/bin/clang",
7+
"cStandard": "c11",
8+
"cppStandard": "c++17",
9+
"intelliSenseMode": "clang-x64",
10+
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
11+
}
12+
],
13+
"version": 4
14+
}

CMakeLists.txt

+37-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1-
cmake_minimum_required(VERSION 3.4...3.18)
2-
project(naive_svg)
1+
cmake_minimum_required(VERSION 3.15...3.26)
2+
if(NOT DEFINED SKBUILD_PROJECT_NAME)
3+
set(SKBUILD_PROJECT_NAME "naive_svg")
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)
616
set(CMAKE_INCLUDE_CURRENT_DIR ON)
717
set(CMAKE_CXX_STANDARD 14)
818

19+
# set(CMAKE_BUILD_TYPE "Debug")
20+
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
21+
set(CMAKE_BUILD_TYPE
22+
"Release"
23+
CACHE STRING "" FORCE)
24+
message(STATUS "Set build type to default: ${CMAKE_BUILD_TYPE}")
25+
else()
26+
message(STATUS "Your build type: ${CMAKE_BUILD_TYPE}")
27+
endif()
28+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
29+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb")
31+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
32+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
33+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
34+
endif()
35+
36+
# https://scikit-build-core.readthedocs.io/en/latest/getting_started.html
37+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
38+
find_package(pybind11 CONFIG REQUIRED)
939
include_directories(headers/include)
1040

11-
set(PYBIND11_CPP_STANDARD -std=c++14)
12-
add_subdirectory(pybind11)
1341
file(GLOB SRCS src/*.cpp)
14-
pybind11_add_module(_naive_svg ${SRCS})
15-
16-
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
17-
# define (VERSION_INFO) here.
18-
target_compile_definitions(_naive_svg
19-
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
42+
python_add_library(_core MODULE ${SRCS} WITH_SOABI)
43+
target_link_libraries(_core PRIVATE pybind11::headers)
44+
target_include_directories(_core PRIVATE src)
45+
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
46+
install(TARGETS _core DESTINATION ${PROJECT_NAME})

Makefile

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT_SOURCE_DIR ?= $(abspath ./)
22
PROJECT_NAME ?= $(shell basename $(PROJECT_SOURCE_DIR))
3+
NUM_JOBS ?= 8
34

45
all:
56
@echo nothing special
@@ -14,11 +15,7 @@ lint:
1415
pre-commit run -a
1516
lint_install:
1617
pre-commit install
17-
18-
build:
19-
mkdir -p build && cd build && \
20-
cmake .. && make
21-
.PHONY: build
18+
.PHONY: lint lint_install
2219

2320
docs_build:
2421
python3 -m pip install -r docs/requirements.txt
@@ -28,7 +25,7 @@ docs_serve:
2825
mkdocs serve -a 0.0.0.0:8088
2926

3027
DOCKER_TAG_WINDOWS ?= ghcr.io/cubao/build-env-windows-x64:v0.0.1
31-
DOCKER_TAG_LINUX ?= ghcr.io/cubao/build-env-manylinux2014-x64:v0.0.4
28+
DOCKER_TAG_LINUX ?= ghcr.io/cubao/build-env-manylinux2014-x64:v0.0.5
3229
DOCKER_TAG_MACOS ?= ghcr.io/cubao/build-env-macos-arm64:v0.0.1
3330

3431
test_in_win:
@@ -48,27 +45,31 @@ test_in_dev_container:
4845
-v `pwd`:`pwd` -w `pwd` -it $(DEV_CONTAINER_IMAG) bash
4946

5047
PYTHON ?= python3
48+
build:
49+
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec pybind11
50+
CMAKE_BUILD_PARALLEL_LEVEL=$(NUM_JOBS) $(PYTHON) -m pip install --no-build-isolation -Ceditable.rebuild=true -Cbuild-dir=build -ve.
5151
python_install:
52-
$(PYTHON) setup.py install
53-
python_build:
54-
$(PYTHON) setup.py bdist_wheel
52+
$(PYTHON) -m pip install . --verbose
53+
python_wheel:
54+
$(PYTHON) -m pip wheel . -w build --verbose
5555
python_sdist:
56-
$(PYTHON) setup.py sdist
57-
python_test:
56+
$(PYTHON) -m pip sdist . --verbose
57+
python_test: pytest
58+
pytest:
5859
python3 -m pip install pytest
59-
pytest tests
60+
pytest tests/test_basic.py
61+
.PHONY: build
62+
63+
restub:
64+
pybind11-stubgen naive_svg._core -o stubs
65+
cp stubs/naive_svg/_core.pyi src/naive_svg
6066

61-
# conda create -y -n py36 python=3.6
62-
# conda create -y -n py37 python=3.7
6367
# conda create -y -n py38 python=3.8
6468
# conda create -y -n py39 python=3.9
6569
# conda create -y -n py310 python=3.10
6670
# conda create -y -n py311 python=3.11
71+
# conda create -y -n py312 python=3.12
6772
# 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
7273
python_build_py38:
7374
PYTHON=python conda run --no-capture-output -n py38 make python_build
7475
python_build_py39:
@@ -77,10 +78,12 @@ python_build_py310:
7778
PYTHON=python conda run --no-capture-output -n py310 make python_build
7879
python_build_py311:
7980
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
81+
python_build_py312:
82+
PYTHON=python conda run --no-capture-output -n py312 make python_build
83+
python_build_all: python_build_py38 python_build_py39 python_build_py310 python_build_py311 python_build_py312
8184
python_build_all_in_linux:
8285
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) make python_build_all repair_wheels
83-
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310 python_build_py311
86+
python_build_all_in_macos: python_build_py38 python_build_py39 python_build_py310 python_build_py311 python_build_py312
8487
python_build_all_in_windows: python_build_all
8588

8689
repair_wheels:

naive_svg/__init__.py

-2
This file was deleted.

pybind11

-1
This file was deleted.

pyproject.toml

+72-28
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,92 @@
11
[build-system]
2-
requires = [
3-
"setuptools>=42",
4-
"wheel",
5-
"ninja",
6-
"cmake>=3.12",
2+
requires = ["scikit-build-core>=0.3.3", "pybind11"]
3+
build-backend = "scikit_build_core.build"
4+
5+
6+
[project]
7+
name = "naive_svg"
8+
version = "0.0.3"
9+
url = "https://github.com/cubao/pybind11-naive-svg"
10+
description="naive svg writer"
11+
readme = "README.md"
12+
authors = [
13+
{ name = "district10", email = "[email protected]" },
14+
]
15+
requires-python = ">=3.7"
16+
classifiers = [
17+
"Development Status :: 4 - Beta",
18+
"License :: OSI Approved :: MIT License",
19+
"Programming Language :: Python :: 3 :: Only",
20+
"Programming Language :: Python :: 3.7",
21+
"Programming Language :: Python :: 3.8",
22+
"Programming Language :: Python :: 3.9",
23+
"Programming Language :: Python :: 3.10",
24+
"Programming Language :: Python :: 3.11",
25+
"Programming Language :: Python :: 3.12",
726
]
8-
build-backend = "setuptools.build_meta"
927

10-
[tool.mypy]
11-
files = "setup.py"
12-
python_version = "3.7"
13-
strict = true
14-
show_error_codes = true
15-
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
16-
warn_unreachable = true
28+
[project.optional-dependencies]
29+
test = ["pytest", "scipy"]
30+
31+
32+
[tool.scikit-build]
33+
wheel.expand-macos-universal-tags = true
1734

18-
[[tool.mypy.overrides]]
19-
module = ["ninja"]
20-
ignore_missing_imports = true
2135

2236
[tool.pytest.ini_options]
2337
minversion = "6.0"
2438
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
2539
xfail_strict = true
26-
filterwarnings = ["error"]
40+
log_cli_level = "INFO"
41+
filterwarnings = [
42+
"error",
43+
]
2744
testpaths = ["tests"]
2845

46+
2947
[tool.cibuildwheel]
3048
test-command = "pytest {project}/tests"
3149
test-extras = ["test"]
3250
test-skip = ["*universal2:arm64"]
33-
# Setuptools bug causes collision between pypy and cpython artifacts
34-
before-build = "rm -rf {project}/build"
51+
build-verbosity = 1
52+
3553

3654
[tool.ruff]
55+
src = ["src"]
56+
57+
[tool.ruff.lint]
58+
exclude = ["*.pyi"]
3759
extend-select = [
38-
"B", # flake8-bugbear
39-
"B904",
40-
"I", # isort
41-
"PGH", # pygrep-hooks
42-
"RUF", # Ruff-specific
43-
"UP", # pyupgrade
60+
"B", # flake8-bugbear
61+
"I", # isort
62+
"ARG", # flake8-unused-arguments
63+
"C4", # flake8-comprehensions
64+
"EM", # flake8-errmsg
65+
"ICN", # flake8-import-conventions
66+
"G", # flake8-logging-format
67+
"PGH", # pygrep-hooks
68+
"PIE", # flake8-pie
69+
"PL", # pylint
70+
"PT", # flake8-pytest-style
71+
"PTH", # flake8-use-pathlib
72+
"RET", # flake8-return
73+
"RUF", # Ruff-specific
74+
"SIM", # flake8-simplify
75+
"T20", # flake8-print
76+
"UP", # pyupgrade
77+
"YTT", # flake8-2020
78+
"EXE", # flake8-executable
79+
"NPY", # NumPy specific rules
80+
"PD", # pandas-vet
4481
]
45-
extend-ignore = [
46-
"E501", # Line too long
82+
ignore = [
83+
"PLR09", # Too many X
84+
"PLR2004", # Magic comparison
85+
"PTH100",
86+
"PTH103",
87+
"PTH120",
4788
]
48-
target-version = "py37"
89+
isort.required-imports = ["from __future__ import annotations"]
90+
91+
[tool.ruff.lint.per-file-ignores]
92+
"tests/**" = ["T20"]

0 commit comments

Comments
 (0)