Skip to content

Commit

Permalink
init project (#2)
Browse files Browse the repository at this point in the history
* init

* update

* not ready

* add makefile

* lint

* not ready

* fix

* fix

* good

---------

Co-authored-by: TANG ZHIXIONG <[email protected]>
  • Loading branch information
district10 and zhixiong-tang authored May 17, 2024
1 parent 66b1c48 commit b5c1e76
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 1,052 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BasedOnStyle: Google
AccessModifierOffset: -2
ColumnLimit: 120
IndentWidth: 4
Language: Cpp
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/conda.yml

This file was deleted.

60 changes: 0 additions & 60 deletions .github/workflows/enscripten.yaml

This file was deleted.

13 changes: 5 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ repos:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
exclude: ^conda\.recipe/meta\.yaml$
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
Expand All @@ -47,7 +45,7 @@ repos:
rev: v1.5.5
hooks:
- id: remove-tabs
exclude: ^(docs)
exclude: ^(docs|Makefile)

# CMake formatting
- repo: https://github.com/cheshirekow/cmake-format-precommit
Expand All @@ -58,8 +56,7 @@ repos:
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$

# Suggested hook if you add a .clang-format file
# - repo: https://github.com/pre-commit/mirrors-clang-format
# rev: v13.0.0
# hooks:
# - id: clang-format
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.0
hooks:
- id: clang-format
32 changes: 21 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
# Require CMake 3.15+ (matching scikit-build-core) Use new versions of all
# policies up to CMake 3.27
cmake_minimum_required(VERSION 3.15...3.27)

# Scikit-build-core sets these values for you, or you can just hard-code the
# name and version.
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)

# Find the module development requirements (requires FindPython from 3.17 or
# scikit-build-core's built-in backport)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 14)

# set(CMAKE_BUILD_TYPE "Debug")
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "" FORCE)
message(STATUS "Set build type to default: ${CMAKE_BUILD_TYPE}")
else()
message(STATUS "Your build type: ${CMAKE_BUILD_TYPE}")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()

find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

# Add a library using FindPython's tooling (pybind11 also provides a helper like
# this)
python_add_library(_core MODULE src/main.cpp WITH_SOABI)
target_link_libraries(_core PRIVATE pybind11::headers)

# This is passing in the version as a define just as an example
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})

# The install directory is the output (wheel) directory
install(TARGETS _core DESTINATION scikit_build_example)
install(TARGETS _core DESTINATION fast_viterbi)
105 changes: 105 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
PROJECT_SOURCE_DIR ?= $(abspath ./)
PROJECT_NAME ?= $(shell basename $(PROJECT_SOURCE_DIR))
NUM_JOBS ?= 8

all:
@echo nothing special

lint:
pre-commit run -a
lint_install:
pre-commit install
.PHONY: lint

reset_submodules:
git submodule update --init --recursive

clean:
rm -rf build *.egg-info dist
force_clean:
docker run --rm -v `pwd`:`pwd` -w `pwd` -it alpine/make make clean

pytest:
python3 -m pip install pytest numpy
pytest tests # --capture=tee-sys
.PHONY: test pytest

docs_build:
mkdocs build
docs_serve:
mkdocs serve -a 0.0.0.0:8088

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.4
DOCKER_TAG_MACOS ?= ghcr.io/cubao/build-env-macos-arm64:v0.0.1

test_in_win:
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/win:`pwd`/build -it $(DOCKER_TAG_WINDOWS) bash
test_in_mac:
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/mac:`pwd`/build -it $(DOCKER_TAG_MACOS) bash
test_in_linux:
docker run --rm -w `pwd` -v `pwd`:`pwd` -v `pwd`/build/linux:`pwd`/build -it $(DOCKER_TAG_LINUX) bash

DEV_CONTAINER_NAME ?= $(USER)_$(subst /,_,$(PROJECT_NAME)____$(PROJECT_SOURCE_DIR))
DEV_CONTAINER_IMAG ?= $(DOCKER_TAG_LINUX)
test_in_dev_container:
docker ps | grep $(DEV_CONTAINER_NAME) \
&& docker exec -it $(DEV_CONTAINER_NAME) bash \
|| docker run --rm --name $(DEV_CONTAINER_NAME) \
--network host --security-opt seccomp=unconfined \
-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) -m pip install . --verbose
python_wheel:
$(PYTHON) -m pip wheel . -w dist --verbose
python_build: python_wheel
python_sdist:
$(PYTHON) -m pip sdist . --verbose
python_test: pytest
.PHONY: build

# 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 env list
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_py37 python_build_py38 python_build_py39 python_build_py310
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_all_in_windows: python_build_all

repair_wheels:
python -m pip install auditwheel # sudo apt install patchelf, conda install -c conda-forge patchelf
ls dist/*-linux_x86_64.whl | xargs -n1 auditwheel repair --plat manylinux2014_x86_64
rm -rf dist/*-linux_x86_64.whl && cp wheelhouse/*.whl dist && rm -rf wheelhouse

pypi_remote ?= pypi
upload_wheels:
python -m pip install twine
twine upload dist/fast_viterbi-*.whl -r $(pypi_remote)

tar.gz:
tar -cvz --exclude .git -f ../$(PROJECT_NAME).tar.gz .
ls -alh ../$(PROJECT_NAME).tar.gz

# https://stackoverflow.com/a/25817631
echo-% : ; @echo -n $($*)
Echo-% : ; @echo $($*)
ECHO-% : ; @echo $* = $($*)
echo-Tab: ; @echo -n ' '
Loading

0 comments on commit b5c1e76

Please sign in to comment.