Skip to content

Commit f1e9570

Browse files
committed
Merge branch 'master' of github.com:sandialabs/SpecUtils
2 parents 9e00e5a + e6773e6 commit f1e9570

25 files changed

+1944
-17009
lines changed

.github/workflows/pip.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# From https://github.com/wjakob/nanobind_example/blob/5ce5ce57143a469e92d9ebaee9c47949ee77caa8/.github/workflows/pip.yml
2+
name: Pip
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
name: Build with Pip
14+
runs-on: ${{ matrix.platform }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
platform: [windows-latest, macos-latest, ubuntu-latest]
19+
#python-version: ["3.9", "3.12"]
20+
python-version: ["3.12"]
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Set min macOS version
30+
if: runner.os == 'macOS'
31+
run: |
32+
echo "MACOSX_DEPLOYMENT_TARGET=10.14" >> $GITHUB_ENV
33+
34+
- name: Build and install
35+
run: |
36+
python -m pip install pytest
37+
pip install --verbose ./bindings/python
38+
39+
- name: Test
40+
run: python -m unittest discover ./bindings/python/tests

.github/workflows/wheels.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# From https://github.com/wjakob/nanobind_example/blob/5ce5ce57143a469e92d9ebaee9c47949ee77caa8/.github/workflows/wheels.yml
2+
3+
name: Wheels
4+
5+
on:
6+
workflow_dispatch:
7+
pull_request:
8+
push:
9+
branches:
10+
- master
11+
release:
12+
types:
13+
- published
14+
15+
jobs:
16+
build_sdist:
17+
name: Build SDist
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
submodules: true
23+
24+
- name: Build SDist
25+
run: pipx run build --sdist ./bindings/python
26+
27+
- name: Check metadata
28+
run: pipx run twine check ./bindings/python/dist/*
29+
30+
- uses: actions/upload-artifact@v4
31+
with:
32+
name: dist-sdist
33+
path: dist/*.tar.gz
34+
35+
36+
build_wheels:
37+
name: Wheels on ${{ matrix.os }}
38+
runs-on: ${{ matrix.os }}
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
os: [ubuntu-latest, macos-13, macos-14, macos-latest, windows-latest]
43+
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
submodules: true
48+
49+
- uses: pypa/[email protected]
50+
env:
51+
CIBW_ARCHS_MACOS: "universal2"
52+
with:
53+
package-dir: ./bindings/python
54+
55+
- name: Verify clean directory
56+
run: git diff --exit-code
57+
shell: bash
58+
59+
- name: Upload wheels
60+
uses: actions/upload-artifact@v4
61+
with:
62+
path: wheelhouse/*.whl
63+
name: dist-${{ matrix.os }}
64+
65+
upload_all:
66+
name: Upload if release
67+
needs: [build_wheels, build_sdist]
68+
runs-on: ubuntu-latest
69+
environment:
70+
name: pypi
71+
url: https://pypi.org/p/SandiaSpecUtils
72+
permissions:
73+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
74+
if: github.event_name == 'release' && github.event.action == 'published'
75+
76+
steps:
77+
- uses: actions/setup-python@v5
78+
- uses: actions/download-artifact@v4
79+
with:
80+
pattern: dist-*
81+
merge-multiple: true
82+
- shell: bash
83+
run: |
84+
pwd
85+
ls
86+
87+
- uses: pypa/gh-action-pypi-publish@release/v1
88+
with:
89+
packages-dir: /home/runner/work/SpecUtils/SpecUtils
90+
user: __token__
91+
password: ${{ secrets.pypi_password }}

CMakeLists.txt

+7-41
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,13 @@ option( SpecUtils_BUILD_UNIT_TESTS "Builds unit tests" OFF )
1919
option( SpecUtils_BUILD_FUZZING_TESTS "Builds fuzzing tests, requires clang" OFF )
2020
option( SpecUtils_BUILD_REGRESSION_TEST "Creates executable to perform interactive regression test" OFF )
2121
option( SpecUtils_BUILD_EXAMPLE "Builds example SpecUtil applications" OFF )
22-
option( SpecUtils_PYTHON_BINDINGS "Creates python bindings to the c++ code" OFF )
2322
option( SpecUtils_JAVA_SWIG "Creates swig/java bindings to the c++ code" OFF )
2423
option( SpecUtils_C_BINDINGS "Creates C bindings to the c++ code" OFF )
2524
option( SpecUtils_INJA_TEMPLATES "Creates inja template interface" OFF )
2625
option( SpecUtils_USE_SIMD "Use SIMD operations; i386/x64 only right now, and very alpha, and extremely minimally used" OFF )
2726
option( SpecUtils_ENABLE_EQUALITY_CHECKS "Enables the equal_enough(...) functions for comparing two spectrum files." OFF ) #code size is only reason to default to off, I think
2827
option( PERFORM_DEVELOPER_CHECKS "Performs additional computationally expensive tests during execution (requires linking to boost)" OFF )
29-
30-
31-
if( SpecUtils_PYTHON_BINDINGS )
32-
option( SpecUtils_SHARED_LIB "Whether to compile a shared, or static library" ON )
33-
list( APPEND sources bindings/python/SpecFile_py.cpp )
34-
else()
35-
#default to building a static lib
36-
option( SpecUtils_SHARED_LIB "Whether to compile a shared, or static library" OFF )
37-
endif()
28+
option( SpecUtils_SHARED_LIB "Whether to compile a shared, or static library" OFF )
3829

3930

4031
set( SpecUtils_FLT_PARSE_METHOD "default_value" CACHE STRING [[How to parse lists of numbers.
@@ -82,7 +73,7 @@ endif()
8273

8374

8475
# If we are building this on Windows, not as a sub-project, lets enable selecting C++ runtime
85-
if( MSVC AND (SpecUtils_PYTHON_BINDINGS OR SpecUtils_BUILD_UNIT_TESTS) )
76+
if( MSVC AND SpecUtils_BUILD_UNIT_TESTS )
8677
get_directory_property(hasParent PARENT_DIRECTORY)
8778
if(NOT hasParent)
8879
option(${PROJECT_NAME}_USE_MSVC_MultiThreadDLL "Use dynamically-link runtime library." OFF)
@@ -96,7 +87,7 @@ if( MSVC AND (SpecUtils_PYTHON_BINDINGS OR SpecUtils_BUILD_UNIT_TESTS) )
9687
endif()
9788
message(STATUS "Using CMAKE_MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY}")
9889
endif(NOT hasParent)
99-
endif( MSVC AND (SpecUtils_PYTHON_BINDINGS OR SpecUtils_BUILD_UNIT_TESTS) )
90+
endif( MSVC AND SpecUtils_BUILD_UNIT_TESTS )
10091

10192

10293
if( SpecUtils_BUILD_EXAMPLE )
@@ -121,14 +112,6 @@ endif( SpecUtils_JAVA_SWIG )
121112

122113
set( THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty" )
123114

124-
if( SpecUtils_PYTHON_BINDINGS )
125-
FIND_PACKAGE(Python3 COMPONENTS Development )
126-
IF(NOT Python3_FOUND)
127-
MESSAGE(FATAL_ERROR "Unable to find PythonLibs.")
128-
ENDIF()
129-
message( "Python include dirs: ${Python3_INCLUDE_DIRS}")
130-
endif()
131-
132115
set( sources
133116
src/SpecFile.cpp
134117
src/SpecFile_pcf.cpp
@@ -255,10 +238,6 @@ if( SpecUtils_ENABLE_URI_SPECTRA )
255238
find_package( ZLIB REQUIRED )
256239
endif( SpecUtils_ENABLE_URI_SPECTRA )
257240

258-
if( SpecUtils_PYTHON_BINDINGS )
259-
list( APPEND sources bindings/python/SpecFile_py.cpp )
260-
endif( SpecUtils_PYTHON_BINDINGS )
261-
262241
if( SpecUtils_JAVA_SWIG )
263242
list( APPEND sources bindings/swig/SpecUtils.i )
264243
endif( SpecUtils_JAVA_SWIG )
@@ -277,7 +256,6 @@ endif( SpecUtils_SHARED_LIB )
277256
add_library( SpecUtils ${SpecUtils_LIB_TYPE} ${sources} ${headers} ${OTHER_SUPPORT_FILES} )
278257
set_target_properties( SpecUtils PROPERTIES PREFIX "lib" OUTPUT_NAME "SpecUtils" )
279258

280-
281259
set( SpecUtils_USE_FAST_FLOAT OFF ) # Uses https://github.com/fastfloat/fast_float . If fast_float.h isnt found, will be fetched
282260
set( SpecUtils_USE_FROM_CHARS OFF ) # Supported by MSVC >= 2019, and gcc >= 12. Not supported by Apple clang. In MSVC, about 50% slower than boost::spirit
283261
set( SpecUtils_USE_BOOST_SPIRIT OFF ) # Uses boost::spirit, and fasted method (maybe a hair faster than fastfloat)
@@ -335,28 +313,22 @@ if( SpecUtils_USE_FAST_FLOAT )
335313
endif( NOT FAST_FLOAT_FILE_PATH )
336314
endif( SpecUtils_USE_FAST_FLOAT )
337315

338-
# We only need boost libraries if we are using boost to parse floats, if we are performing developer
339-
# checks, or we are creating Python bindings
340-
if( SpecUtils_USE_BOOST_SPIRIT OR PERFORM_DEVELOPER_CHECKS OR SpecUtils_PYTHON_BINDINGS )
316+
# We only need boost libraries if we are using boost to parse floats, if we are performing developer checks
317+
if( SpecUtils_USE_BOOST_SPIRIT OR PERFORM_DEVELOPER_CHECKS )
341318

342319
if( DEFINED boost_SOURCE_DIR )
343320
# We used CMake Fetch to get boost (e.g., in InterSpec)
344321
target_link_libraries( SpecUtils PUBLIC Boost::system Boost::spirit Boost::fusion Boost::algorithm Boost::functional Boost::crc )
345322

346323
else( DEFINED boost_SOURCE_DIR )
347-
348-
if( SpecUtils_PYTHON_BINDINGS )
349-
list( APPEND boost_libs_required python )
350-
endif( SpecUtils_PYTHON_BINDINGS )
351-
352324
find_package( Boost REQUIRED COMPONENTS system ${boost_libs_required} )
353325
if( NOT Boost_FOUND )
354326
message(FATAL_ERROR "Couldnt Find Boost")
355327
endif( NOT Boost_FOUND )
356328

357329
target_link_libraries( SpecUtils PUBLIC Boost::system )
358330
endif( DEFINED boost_SOURCE_DIR )
359-
endif( SpecUtils_USE_BOOST_SPIRIT OR PERFORM_DEVELOPER_CHECKS OR SpecUtils_PYTHON_BINDINGS )
331+
endif( SpecUtils_USE_BOOST_SPIRIT OR PERFORM_DEVELOPER_CHECKS )
360332

361333
if( SpecUtils_USE_FROM_CHARS )
362334
if( NOT (MSVC AND (MSVC_VERSION GREATER_EQUAL 1920)) )
@@ -402,17 +374,11 @@ elseif( NOT SpecUtils_USING_NO_THREADING )
402374
endif( SpecUtils_USE_WT_THREADPOOL )
403375

404376

405-
406377
if( SpecUtils_ENABLE_URI_SPECTRA )
407378
target_link_libraries( SpecUtils PUBLIC ZLIB::ZLIB )
408379
endif( SpecUtils_ENABLE_URI_SPECTRA )
409380

410381

411-
if( SpecUtils_PYTHON_BINDINGS )
412-
target_link_libraries( SpecUtils PUBLIC Boost::python ${Boost_PYTHON_LIBRARY} ${Python3_LIBRARIES} )
413-
endif( SpecUtils_PYTHON_BINDINGS )
414-
415-
416382
if( SpecUtils_JAVA_SWIG )
417383
target_link_libraries( SpecUtils PUBLIC ${JAVA_LIBRARIES} )
418384
endif( SpecUtils_JAVA_SWIG )
@@ -428,7 +394,7 @@ elseif( WIN32 )
428394
endif( MINGW )
429395

430396
target_include_directories( SpecUtils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
431-
PRIVATE ${THIRD_PARTY_DIR} ${Python3_INCLUDE_DIRS} )
397+
PRIVATE ${THIRD_PARTY_DIR} )
432398

433399
if( SpecUtils_BUILD_REGRESSION_TEST )
434400
if( NOT SpecUtils_ENABLE_EQUALITY_CHECKS )

bindings/python/CMakeLists.txt

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
cmake_minimum_required(VERSION 3.15...3.26)
2+
3+
project(SpecUtils_py LANGUAGES CXX)
4+
5+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6+
7+
set( SpecUtils_ENABLE_D3_CHART ON CACHE BOOL "" )
8+
set( SpecUtils_D3_SUPPORT_FILE_STATIC ON CACHE BOOL "" )
9+
set( SpecUtils_ENABLE_URI_SPECTRA OFF CACHE BOOL "" ) #Lets not worry about linking to zlib right now
10+
set( SpecUtils_PYTHON_BINDINGS ON CACHE BOOL "Build the python bindings" )
11+
set( SpecUtils_ENABLE_EQUALITY_CHECKS OFF CACHE BOOL "" )
12+
set( PERFORM_DEVELOPER_CHECKS OFF CACHE BOOL "" )
13+
set( SpecUtils_SHARED_LIB OFF CACHE BOOL "" ) #we'll statically link SpecUtils into the lib we create here
14+
set( SpecUtils_FLT_PARSE_METHOD "strtod" CACHE STRING "Float parsing method" )
15+
16+
add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/LibSpecUtils )
17+
18+
if (NOT SKBUILD)
19+
message(FATAL_ERROR "\
20+
This CMake file is must be executed using 'scikit-build'.
21+
If you are a user trying to install this package, please use the command
22+
below, which will install all necessary build dependencies, compile
23+
the package in an isolated environment, and then install it.
24+
=====================================================================
25+
$ pip install .
26+
=====================================================================
27+
If you are a software developer, and this is your own package, then
28+
it is usually much more efficient to install the build dependencies
29+
in your environment once and use the following command that avoids
30+
a costly creation of a new virtual environment at every compilation:
31+
=====================================================================
32+
$ pip install nanobind scikit-build-core
33+
$ pip install --no-build-isolation -ve .
34+
=====================================================================
35+
You may optionally add -Ceditable.rebuild=true to auto-rebuild when
36+
the package is imported. Otherwise, you need to re-run the above
37+
after editing C++ files.")
38+
endif()
39+
40+
# Try to import all Python components potentially needed by nanobind
41+
find_package(Python 3.8
42+
REQUIRED COMPONENTS Interpreter Development.Module
43+
OPTIONAL_COMPONENTS Development.SABIModule)
44+
45+
# Import nanobind through CMake's find_package mechanism
46+
find_package(nanobind CONFIG REQUIRED)
47+
48+
# We are now ready to compile the actual extension module
49+
nanobind_add_module(
50+
# Name of the extension
51+
PySpecUtils
52+
53+
# Target the stable ABI for Python 3.12+, which reduces
54+
# the number of binary wheels that must be built. This
55+
# does nothing on older Python versions
56+
STABLE_ABI
57+
58+
# Build libnanobind statically and merge it into the
59+
# extension (which itself remains a shared library)
60+
#
61+
# If your project builds multiple extensions, you can
62+
# replace this flag by NB_SHARED to conserve space by
63+
# reusing a shared libnanobind across libraries
64+
NB_STATIC
65+
66+
#Perform link time optimization.
67+
#LTO
68+
69+
70+
# Source code goes here
71+
SpecFile_py.cpp
72+
)
73+
74+
set_target_properties( PySpecUtils PROPERTIES OUTPUT_NAME "SpecUtils" )
75+
target_link_libraries( PySpecUtils PUBLIC SpecUtils )
76+
77+
# Install directive for scikit-build-core
78+
install(TARGETS PySpecUtils LIBRARY DESTINATION SpecUtils)
79+
install(FILES __init__.py DESTINATION SpecUtils)
80+
81+
nanobind_add_stub(
82+
SpecUtils_stub
83+
MODULE SpecUtils
84+
OUTPUT SpecUtils.pyi
85+
PYTHON_PATH $<TARGET_FILE_DIR:PySpecUtils>
86+
DEPENDS PySpecUtils
87+
)

bindings/python/Ex_pyconverted.chn

-64.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)