Skip to content

Commit df3746a

Browse files
authored
Convert to pyproject, add type hints, use CMake (#13)
1 parent e49c750 commit df3746a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2541
-2384
lines changed

.github/workflows/build.yml

Lines changed: 92 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,109 @@ on:
88
branches: [ main ]
99

1010
jobs:
11-
12-
build:
11+
lint:
12+
runs-on: ubuntu-22.04
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: astral-sh/ruff-action@v3
16+
- run: ruff check
17+
- run: ruff format --check --diff
18+
build-binaries:
19+
needs: [ lint ]
1320
strategy:
1421
matrix:
1522
include:
16-
- name: x86-windows
17-
image: windows-2022
18-
arch: x86
23+
- name: x86_64-linux
24+
image: ubuntu-22.04
25+
cmake-args: -D ARCHITECTURE=x86_64
1926
- name: x86_64-windows
2027
image: windows-2022
21-
arch: x86_64
22-
- name: x86_64-linux
23-
image: ubuntu-20.04
24-
arch: x86_64
28+
cmake-args: -A x64 -D ARCHITECTURE=x86_64
2529
- name: x86_64-darwin
26-
image: macos-12
27-
arch: x86_64
30+
image: macos-13
31+
cmake-args: -D CMAKE_OSX_ARCHITECTURES=x86_64 -D ARCHITECTURE=x86_64
32+
- name: aarch64-darwin
33+
image: macos-13
34+
cmake-args: -D CMAKE_OSX_ARCHITECTURES=arm64 -D ARCHITECTURE=aarch64
2835
runs-on: ${{ matrix.image }}
2936
steps:
3037
- name: Checkout repository
3138
uses: actions/checkout@v4
32-
- name: Setup Python
33-
uses: actions/setup-python@v5
34-
with:
35-
python-version: '3.x'
36-
- name: Query Python executable
37-
run: which python
38-
- name: Install dependencies
39-
run: python -m pip install h5py matplotlib numpy pytest scipy setuptools wheel
40-
- name: Build Python Wheel
41-
run: python setup.py bdist_wheel
42-
- name: Install Python Wheel
43-
shell: bash
39+
with:
40+
submodules: true
41+
- name: Build NDTable
4442
run: |
45-
for f in dist/SDF-*-py3-none-any.whl; do
46-
python -m pip install $f --no-deps -vv
47-
done
48-
- name: Run Python tests
49-
run: pytest tests
50-
- name: Upload artifacts
51-
uses: actions/upload-artifact@v4
43+
cmake -S C -B C/${{ matrix.name }} ${{ matrix.cmake-args }}
44+
cmake --build C/${{ matrix.name }} --target install
45+
- uses: actions/upload-artifact@v4
5246
with:
5347
name: ${{ matrix.name }}
54-
path: dist/*.whl
48+
path: src/sdf/ndtable/${{ matrix.name }}
5549
if-no-files-found: error
50+
build-wheel:
51+
runs-on: ubuntu-22.04
52+
needs: [build-binaries]
53+
steps:
54+
- uses: astral-sh/setup-uv@v4
55+
- uses: actions/checkout@v4
56+
- uses: actions/download-artifact@v4
57+
with:
58+
name: x86_64-linux
59+
path: src/sdf/ndtable/x86_64-linux
60+
- uses: actions/download-artifact@v4
61+
- uses: actions/download-artifact@v4
62+
with:
63+
name: x86_64-windows
64+
path: src/sdf/ndtable/x86_64-windows
65+
- uses: actions/download-artifact@v4
66+
with:
67+
name: x86_64-darwin
68+
path: src/sdf/ndtable/x86_64-darwin
69+
- uses: actions/download-artifact@v4
70+
with:
71+
name: aarch64-darwin
72+
path: src/sdf/ndtable/aarch64-darwin
73+
- run: uv build --wheel
74+
- uses: actions/upload-artifact@v4
75+
with:
76+
name: dist
77+
path: dist
78+
if-no-files-found: error
79+
run-tests:
80+
needs: [ build-wheel ]
81+
strategy:
82+
matrix:
83+
include:
84+
- name: x86_64-linux
85+
image: ubuntu-22.04
86+
- name: x86_64-windows
87+
image: windows-2022
88+
- name: x86_64-darwin
89+
image: macos-13
90+
- name: aarch64-darwin
91+
image: macos-13
92+
runs-on: ${{ matrix.image }}
93+
steps:
94+
- uses: actions/checkout@v4
95+
- run: rm pyproject.toml
96+
- uses: astral-sh/setup-uv@v4
97+
- uses: actions/download-artifact@v4
98+
with:
99+
name: dist
100+
- if: matrix.name == 'x86_64-windows'
101+
run: |
102+
uv venv --python 3.10
103+
.venv\Scripts\activate
104+
uv pip install pytest
105+
$files = Get-ChildItem "sdf-*-py3-none-any.whl"
106+
foreach ($f in $files) {
107+
uv pip install $f.FullName
108+
}
109+
uv run pytest
110+
- if: matrix.name != 'x86_64-windows'
111+
run: |
112+
uv venv --python 3.10
113+
source .venv/bin/activate
114+
uv pip install pytest
115+
uv pip install sdf-*-py3-none-any.whl
116+
uv run pytest

.gitignore

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,19 @@
11
# SDF files
22
*.sdf
33

4-
# Build artefacts
5-
*.o
6-
74
# PyCharm projects
85
.idea/
96

10-
# compiled code
11-
*.py[cod]
12-
13-
# Packages
14-
*.egg
15-
*.egg-info
16-
dist
17-
build
18-
eggs
19-
parts
20-
bin
21-
var
22-
sdist
23-
develop-eggs
24-
.installed.cfg
25-
lib
26-
lib64
7+
# Python artifacts
278
__pycache__
289

29-
# Installer logs
30-
pip-log.txt
31-
32-
# Unit test / coverage reports
33-
.coverage
34-
.tox
35-
nosetests.xml
36-
37-
# Translations
38-
*.mo
39-
40-
# data files
41-
*.h5
42-
*.mat
43-
!DoublePendulum.mat
44-
45-
# temp files
46-
~*
47-
48-
# Eclipse user settings
49-
.settings/
50-
51-
# PDFs
52-
*.pdf
53-
54-
# auto generated manifest
55-
MANIFEST
56-
57-
# automation scripts
58-
# *.bat
10+
# native binaries
11+
*.dll
12+
*.dylib
13+
*.lib
14+
*.so
5915

60-
# test file
61-
!IntegerNetwork1.mat
16+
# build artifacts
17+
C/aarch64-*/
18+
C/x86-*/
19+
C/x86_64-*/

C/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required (VERSION 3.20)
2+
3+
cmake_policy(SET CMP0177 NEW)
4+
5+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
6+
# set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
7+
8+
project (NDTable)
9+
10+
set(ARCHITECTURE "" CACHE STRING "Architecture")
11+
set_property(CACHE ARCHITECTURE PROPERTY STRINGS "" "aarch64" "x86" "x86_64")
12+
13+
if (NOT ARCHITECTURE)
14+
if (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "AMD64|x86_64")
15+
set(ARCHITECTURE "x86_64")
16+
elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64")
17+
set(ARCHITECTURE "aarch64")
18+
else ()
19+
message(FATAL_ERROR "Unknown System Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
20+
endif ()
21+
endif ()
22+
23+
if (WIN32)
24+
set(PLATFORM "${ARCHITECTURE}-windows")
25+
elseif (APPLE)
26+
set(PLATFORM "${ARCHITECTURE}-darwin")
27+
else ()
28+
set(PLATFORM "${ARCHITECTURE}-linux")
29+
endif ()
30+
31+
message(STATUS "PLATFORM: ${PLATFORM}")
32+
33+
add_library(NDTable SHARED
34+
"include/Python.h"
35+
"src/Python.c"
36+
"NDTable/include/NDTable.h"
37+
"NDTable/src/Core.c"
38+
"NDTable/src/Interpolation.c"
39+
)
40+
41+
target_include_directories(NDTable PRIVATE
42+
"include"
43+
"NDTable/include"
44+
)
45+
46+
install(TARGETS NDTable DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/../src/sdf/ndtable/${PLATFORM}")

0 commit comments

Comments
 (0)