Skip to content

Commit 2a3f284

Browse files
release to pypi (#4)
* fix test * init from cubao-tippecanoe * clean up * add package * fix * clean up * fix * fix * fix CI --------- Co-authored-by: tang zhixiong <zhixiong.tang@momenta.ai>
1 parent 292ed0d commit 2a3f284

File tree

11 files changed

+260
-54
lines changed

11 files changed

+260
-54
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/pip.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Pip"
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
build:
12+
name: Build with Pip
13+
runs-on: ${{ matrix.platform }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
platform: [macos-latest, ubuntu-latest]
18+
python-version: ["3.9", "3.11"]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
submodules: true
24+
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Build and install
30+
run: pip install --verbose .

.github/workflows/wheels.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Wheels
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
release:
10+
types:
11+
- published
12+
13+
env:
14+
FORCE_COLOR: 3
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build_sdist:
22+
name: Build SDist
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
submodules: true
28+
29+
- name: Build SDist
30+
run: pipx run build --sdist
31+
32+
- name: Check metadata
33+
run: pipx run twine check dist/*
34+
35+
- uses: actions/upload-artifact@v4
36+
with:
37+
name: cibw-sdist
38+
path: dist/*.tar.gz
39+
40+
41+
build_wheels:
42+
name: Wheels on ${{ matrix.os }}
43+
runs-on: ${{ matrix.os }}
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
os: [ubuntu-latest, ubuntu-24.04-arm, macos-14]
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
submodules: true
53+
54+
- uses: pypa/cibuildwheel@v3.3.1
55+
env:
56+
CIBW_ARCHS_MACOS: universal2
57+
CIBW_SKIP: "pp* *musllinux* *_i686 cp314t-win*"
58+
CIBW_TEST_SKIP: "*"
59+
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.14
60+
61+
- name: Verify clean directory
62+
run: git diff --exit-code
63+
shell: bash
64+
65+
- uses: actions/upload-artifact@v4
66+
with:
67+
name: cibw-wheels-${{ matrix.os }}
68+
path: wheelhouse/*.whl
69+
70+
71+
upload_all:
72+
name: Upload if release
73+
needs: [build_wheels, build_sdist]
74+
runs-on: ubuntu-latest
75+
if: github.event_name == 'release' && github.event.action == 'published'
76+
environment: pypi
77+
permissions:
78+
id-token: write
79+
80+
steps:
81+
- uses: actions/setup-python@v5
82+
with:
83+
python-version: "3.x"
84+
85+
- uses: actions/download-artifact@v4
86+
with:
87+
pattern: cibw-*
88+
merge-multiple: true
89+
path: dist
90+
91+
- uses: pypa/gh-action-pypi-publish@release/v1
92+
with:
93+
password: ${{ secrets.pypi_password }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
build/
3535
.cache
3636
profiler_report.json
37+
__pycache__/
38+
*.pyc
39+
dist

CMakeLists.txt

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

416
# Set C++ standard
517
set(CMAKE_CXX_STANDARD 17)
@@ -10,6 +22,11 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1022
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1123
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1224

25+
# std::visit requires macOS 10.14+
26+
if(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "10.14")
27+
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum macOS deployment version" FORCE)
28+
endif()
29+
1330
# set(CMAKE_BUILD_TYPE "Debug")
1431
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
1532
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
@@ -51,14 +68,25 @@ if(NOT SHOW_XTENSOR_WARNINGS)
5168
endif()
5269

5370
# Create numpy static library
54-
add_library(${PROJECT_NAME} STATIC src/numpy.cpp)
71+
add_library(numpy STATIC src/numpy.cpp)
5572

5673
# Define PY_DYNAMIC_MODULE for numpy
57-
target_compile_definitions(${PROJECT_NAME} PRIVATE PY_DYNAMIC_MODULE)
74+
target_compile_definitions(numpy PRIVATE PY_DYNAMIC_MODULE)
5875

5976
# Link numpy with pocketpy
60-
target_link_libraries(${PROJECT_NAME} PUBLIC pocketpy)
77+
target_link_libraries(numpy PUBLIC pocketpy)
6178

6279
add_executable(pocketpy_cli src/main.cpp)
6380
set_target_properties(pocketpy_cli PROPERTIES OUTPUT_NAME pocketpy)
64-
target_link_libraries(pocketpy_cli ${PROJECT_NAME})
81+
set_target_properties(pocketpy_cli PROPERTIES SUFFIX ".exe")
82+
target_link_libraries(pocketpy_cli numpy)
83+
install(TARGETS pocketpy_cli DESTINATION ${PROJECT_NAME})
84+
85+
# https://scikit-build-core.readthedocs.io/en/latest/getting_started.html
86+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
87+
find_package(pybind11 CONFIG REQUIRED)
88+
89+
python_add_library(_core MODULE src/pybind.cpp WITH_SOABI)
90+
target_link_libraries(_core PRIVATE pybind11::headers)
91+
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
92+
install(TARGETS _core DESTINATION ${PROJECT_NAME})

Makefile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
PROJECT_SOURCE_DIR ?= $(abspath ./)
2+
PROJECT_NAME ?= $(shell basename $(PROJECT_SOURCE_DIR))
3+
NUM_JOB ?= 8
4+
15
all:
26
@echo nothing special
37
.PHONY: all
48

59
clean:
6-
rm -rf build
10+
rm -rf build dist
711
.PHONY: clean
812

13+
PYTHON ?= python3
914
build:
10-
cmake -B build -DCMAKE_BUILD_TYPE=Release
11-
cmake --build build --config Release
12-
.PHONY: build
15+
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec pybind11
16+
CMAKE_BUILD_PARALLEL_LEVEL=$(NUM_JOB) $(PYTHON) -m pip install --no-build-isolation -Ceditable.rebuild=true -Cbuild-dir=build -ve.
17+
python_install:
18+
$(PYTHON) -m pip install . --verbose
19+
python_wheel:
20+
$(PYTHON) -m pip wheel . -w build --verbose
21+
python_sdist:
22+
$(PYTHON) -m build --sdist
23+
test_install:
24+
python3 -m pip install dist/pocket_numpy-*.tar.gz --force-reinstall
25+
.PHONY: build python_install python_wheel python_sdist test_install
1326

1427
test:
15-
build/test_numpy tests/test_numpy.py
28+
build/pocketpy.exe tests/test_numpy.py

pyproject.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[build-system]
2+
requires = ["scikit-build-core>=0.3.3", "pybind11"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "pocket_numpy"
7+
version = "0.0.1"
8+
description = "pocketpy with numpy"
9+
readme = "README.md"
10+
authors = [
11+
{ name = "tzx", email = "dvorak4tzx@gmail.com" },
12+
]
13+
requires-python = ">=3.8"
14+
classifiers = [
15+
"Development Status :: 4 - Beta",
16+
"License :: OSI Approved :: BSD License",
17+
"Programming Language :: Python :: 3 :: Only",
18+
"Programming Language :: Python :: 3.8",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: 3.13",
24+
"Programming Language :: Python :: 3.14",
25+
]
26+
27+
[project.urls]
28+
Homepage = "https://github.com/cubao/xtensor-numpy"
29+
30+
[project.optional-dependencies]
31+
test = ["pytest"]
32+
33+
[tool.scikit-build]
34+
wheel.expand-macos-universal-tags = true
35+
36+
[tool.pytest.ini_options]
37+
minversion = "6.0"
38+
testpaths = ["tests"]
39+
40+
[tool.cibuildwheel]
41+
test-command = "pytest {project}/tests"
42+
test-extras = ["test"]
43+
test-skip = ["*universal2:arm64"]
44+
build-verbosity = 1

src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ int main(int argc, char** argv) {
4040
const char* arg2 = NULL;
4141

4242
for(int i = 1; i < argc; i++) {
43+
if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
44+
printf("Usage: pocketpy [--profile] [--debug] [--compile] filename\n");
45+
printf(" pocketpy --help\n");
46+
return 1;
47+
}
4348
if(strcmp(argv[i], "--profile") == 0) {
4449
profile = true;
4550
continue;

src/pocket_numpy/__init__.py

Whitespace-only changes.

src/pocket_numpy/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
import subprocess
3+
from pathlib import Path
4+
5+
6+
if __name__ == '__main__':
7+
exe = f'{Path(__file__).parent}/pocketpy.exe'
8+
args = sys.argv[1:]
9+
sys.exit(subprocess.call([exe, *args]))

0 commit comments

Comments
 (0)