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

add typing stubs #9

Merged
merged 29 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is a format job. Pre-commit has a first-party GitHub action, so we use
# that: https://github.com/pre-commit/action

name: Format

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
pre-commit:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- uses: pre-commit/[email protected]
37 changes: 37 additions & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Pip

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-20.04, windows-2019, macos-13]
python-version: ["3.9"]

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

steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Add requirements
run: python -m pip install --upgrade wheel setuptools

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

- name: Test
if: ${{ startsWith(matrix.platform, 'ubuntu') }}
run: python -m pytest
93 changes: 93 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Wheels

on:
workflow_dispatch:
pull_request:
push:
branches:
- master
release:
types:
- published

env:
FORCE_COLOR: 3

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

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

- name: Check metadata
run: pipx run twine check dist/*

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz


build_wheels:
name: Wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-13, windows-latest]

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: universal2
CIBW_ARCHS_WINDOWS: auto ARM64
CIBW_SKIP: pp* *i686 *musllinux*
CIBW_TEST_SKIP: "*"

- name: Verify clean directory
run: git diff --exit-code
shell: bash

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}
path: wheelhouse/*.whl


upload_all:
name: Upload if release
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
environment: pypi
permissions:
id-token: write

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

- uses: actions/download-artifact@v4
with:
pattern: cibw-*
merge-multiple: true
path: dist

- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.pypi_password }}
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
7 changes: 0 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,10 +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
[submodule "h3"]
path = h3
url = https://github.com/uber/h3.git
35 changes: 9 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,22 @@ repos:
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
- id: end-of-file-fixer

# Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
exclude: ^(docs)

# Sort your imports in a standard form
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
# Check linting and style issues
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.5"
hooks:
- id: isort

# Upgrade older Python syntax
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
exclude: ^(docs)

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

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
exclude: ^(docs|Makefile|benchmarks/Makefile)

# CMake formatting
- repo: https://github.com/cheshirekow/cmake-format-precommit
Expand All @@ -81,3 +63,4 @@ repos:
rev: v13.0.0
hooks:
- id: clang-format
exclude: ^(src/h3lib)
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@
"future": "cpp",
"regex": "cpp",
"core": "cpp",
"jacobi": "cpp"
"jacobi": "cpp",
"__verbose_abort": "cpp",
"charconv": "cpp",
"execution": "cpp",
"latch": "cpp",
"shared_mutex": "cpp",
"span": "cpp"
},
"workbench.colorCustomizations": {
"activityBar.background": "#143328",
Expand Down
39 changes: 21 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
cmake_minimum_required(VERSION 3.4...3.18)
project(geocondense)
cmake_minimum_required(VERSION 3.15...3.27)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES C CXX)

# set(CMAKE_BUILD_TYPE "Debug")
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE
"Release"
Expand All @@ -20,19 +22,20 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()

include_directories(
${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/h3/src/h3lib/include
${PROJECT_SOURCE_DIR}/headers/include)

configure_file(h3/src/h3lib/include/h3api.h.in ${PROJECT_BINARY_DIR}/h3api.h)
file(GLOB H3SOURCES h3/src/h3lib/lib/*.c)
# add_library(h3 STATIC ${H3SOURCES})

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(PYBIND11_CPP_STANDARD -std=c++17)
add_subdirectory(pybind11)
pybind11_add_module(pybind11_geocondense src/main.cpp ${H3SOURCES})
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/headers/include)
include_directories(${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/src/h3lib/include)

configure_file(src/h3lib/include/h3api.h.in ${PROJECT_BINARY_DIR}/h3api.h)
file(GLOB H3SOURCES src/h3lib/lib/*.c)

# target_link_libraries(pybind11_geocondense h3)
target_compile_definitions(pybind11_geocondense
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
python_add_library(_core MODULE src/main.cpp ${H3SOURCES} WITH_SOABI)
target_link_libraries(_core PRIVATE pybind11::headers)
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
install(TARGETS _core DESTINATION ${PROJECT_NAME})
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

48 changes: 25 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ lint:
pre-commit run -a
lint_install:
pre-commit install

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

DOCKER_TAG_WINDOWS ?= ghcr.io/cubao/build-env-windows-x64:v0.0.1
DOCKER_TAG_LINUX ?= ghcr.io/cubao/build-env-manylinux2014-x64:v0.0.1
DOCKER_TAG_LINUX ?= ghcr.io/cubao/build-env-manylinux2014-x64:v0.0.5
DOCKER_TAG_MACOS ?= ghcr.io/cubao/build-env-macos-arm64:v0.0.1

test_in_arg ?= --rm --name geocondense -w `pwd` -v `pwd`:`pwd`
Expand All @@ -30,40 +26,46 @@ test_in_linux:
docker run $(test_in_arg) -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) 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_fast_install:
$(PYTHON) setup.py install --no-deps
python_build:
$(PYTHON) setup.py bdist_wheel
$(PYTHON) -m pip install . --verbose
python_wheel:
$(PYTHON) -m pip wheel . -w dist --verbose
python_build: python_wheel
python_sdist:
$(PYTHON) setup.py sdist
# tar -tvf dist/geocondense-*.tar.gz
$(PYTHON) -m pip sdist . --verbose
python_test:
pytest --capture=tee-sys tests
test: python_test
$(PYTHON) -m pip install pytest
pytest tests
.PHONY: build python_install python_wheel python_build python_sdist python_test

restub:
pybind11-stubgen geocondense._core -o stubs
cp stubs/geocondense/_core.pyi src/geocondense

# 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:
PYTHON=python conda run --no-capture-output -n py39 make python_build
python_build_py310:
PYTHON=python conda run --no-capture-output -n py310 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=python conda run --no-capture-output -n py311 make python_build
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/win:`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_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: 0 additions & 2 deletions geocondense/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion h3
Submodule h3 deleted from 53b52a
2 changes: 1 addition & 1 deletion headers
Submodule headers updated 1445 files
1 change: 0 additions & 1 deletion pybind11
Submodule pybind11 deleted from 914c06
Loading
Loading