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 first attempt at python library #349

Merged
merged 53 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b163694
add first attempt at python library
phlptp Dec 9, 2024
0f8bbd6
update coverage
phlptp Dec 9, 2024
acb6b03
try using package lcov
phlptp Dec 9, 2024
4ac0f41
play with circle-ci machines see if that changes the sanitizer builds
phlptp Dec 12, 2024
b2916fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2024
5cc9570
try again with sanitizers
phlptp Dec 12, 2024
2199df9
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 12, 2024
d29d2cc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2024
8d7f1a9
try different image
phlptp Dec 12, 2024
27df0b5
change circle machine
phlptp Dec 12, 2024
05140e0
try oldest machine image
phlptp Dec 12, 2024
c7720d1
disable msan and tsan tests due to kernel memory randomization issue.…
phlptp Dec 13, 2024
26a7067
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2024
923f40d
add some python code
phlptp Dec 14, 2024
f596536
more python code
phlptp Dec 15, 2024
53d3bd2
working nanobind generation
phlptp Dec 15, 2024
d72ce60
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 15, 2024
c928d8a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2024
07724c3
move some files around
phlptp Dec 17, 2024
878b833
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 17, 2024
31fe596
adding python workflows
phlptp Dec 18, 2024
310091e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 18, 2024
b54f48a
try using args instead of define
phlptp Dec 18, 2024
301eb8d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 18, 2024
c61c12a
match pyproject with CMakeLists.txt
phlptp Dec 18, 2024
a09ae8c
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 18, 2024
de89a35
update pip workflows
phlptp Dec 18, 2024
11aadae
keep tweaking the python project
phlptp Dec 19, 2024
55e0955
tweak scikit project name
phlptp Dec 19, 2024
bf88c05
tweaking some of the builds
phlptp Dec 19, 2024
3f96f5e
try very verbose
phlptp Dec 19, 2024
64f3372
restructure python directories to better match example
phlptp Dec 20, 2024
e931ec1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
f3ba606
tweak the project to better match example
phlptp Dec 20, 2024
68cb7dd
detect SKBUILD and install differently
phlptp Dec 20, 2024
3d25411
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
a6e8afe
clean up install for SKBUILD and check naming
phlptp Dec 20, 2024
dd286f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
b03291c
add more tests
phlptp Dec 20, 2024
566b7db
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 20, 2024
62fafef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2024
65e8102
add more tests
phlptp Dec 21, 2024
02e5ff6
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 21, 2024
a41e749
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 21, 2024
785e2b2
add wheels publishing
phlptp Dec 21, 2024
4a1330d
Merge branch 'add_python' of https://github.com/LLNL/units into add_p…
phlptp Dec 21, 2024
079ce85
try different download pattern
phlptp Dec 21, 2024
39753fa
update the wheels job
phlptp Dec 21, 2024
6fddcc4
using verbose upload
phlptp Dec 21, 2024
0e2c103
update license classifier to new standard
phlptp Dec 21, 2024
d00aaf9
update pyproject.toml to latest standards
phlptp Dec 21, 2024
152ec08
update minimum macos version supported
phlptp Dec 21, 2024
ac06811
use post version
phlptp Dec 21, 2024
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
12 changes: 9 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ aliases:

jobs:
unitsTSan:
machine:
image: ubuntu-2204:2024.01.2
docker:
- image: helics/buildenv:sanitizers-14
environment:
Expand All @@ -49,8 +51,10 @@ jobs:
- run: *run_units

unitsASan:
machine:
image: ubuntu-2204:2024.11.1
docker:
- image: helics/buildenv:sanitizers-14
- image: helics/buildenv:sanitizers-19
environment:
CMAKE_FLAGS: '-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_FLAGS="-fsanitize=undefined,address -lc++ -lc++abi -fsanitize-address-use-after-scope -Wno-unused-command-line-argument -fno-omit-frame-pointer -g -O1 -fsanitize-blacklist=/root/project/.circleci/asan_blacklist.txt" '
LSAN_OPTIONS: "suppressions=/root/project/.circleci/leak_suppression.txt"
Expand All @@ -62,6 +66,8 @@ jobs:
- run: *run_units

unitsMSan:
machine:
image: ubuntu-2204:2022.10.2
docker:
- image: helics/buildenv:sanitizers-14
environment:
Expand Down Expand Up @@ -110,9 +116,9 @@ workflows:
version: 2
units_test:
jobs:
- unitsMSan
# - unitsMSan
- unitsASan
- unitsTSan
# - unitsTSan
- unitsInstall
- unitsInstall-alt
- unitsFuzz
14 changes: 7 additions & 7 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
coverage:
name: Coverage
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
matrix:
std: ["11", "14", "17", "20"]
Expand All @@ -25,11 +25,11 @@ jobs:

- name: Get LCov
run: |
sudo apt-get install ca-certificates
wget https://github.com/linux-test-project/lcov/releases/download/v1.16/lcov-1.16.tar.gz
tar -xzf lcov-1.16.tar.gz
cd lcov-1.16
sudo make install
sudo apt-get install ca-certificates lcov
#wget https://github.com/linux-test-project/lcov/releases/download/v2.2/lcov-2.2.tar.gz
#tar -xzf lcov-2.2.tar.gz
#cd lcov-2.2
#sudo make install

- name: Configure
run: |
Expand All @@ -54,7 +54,7 @@ jobs:
lcov --list coverage.info
working-directory: build

- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
files: build/coverage.info
fail_ci_if_error: true
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Pip

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

jobs:
build:
name: Build with Pip
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.10", "3.12"]

steps:
- uses: actions/checkout@v4

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

- name: Set min macOS version
if: runner.os == 'macOS'
run: |
echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> $GITHUB_ENV

- name: Build and install
run: |
python -m pip install pytest
pip install -vv .

- name: Test
run: python -m pytest ./test/python
80 changes: 80 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Wheels

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

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: dist-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-14, windows-latest]

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

- uses: pypa/[email protected]

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

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

publish-to-testpypi:
name: Upload if release
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
#if: github.event_name == 'release' && github.event.action == 'published'
environment:
name: testpypi
url: https://test.pypi.org/p/units_llnl
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- uses: actions/setup-python@v5
- uses: actions/download-artifact@v4
with:
pattern: dist-*
merge-multiple: true
path: dist/

- uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
repository-url: https://test.pypi.org/legacy/
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
build*/
~$.xlsx
~$*.xlsx
nanobind_test.egg-info
_skbuild
/dist
__pycache__
build
*.pyd
*.egg-info
.vscode
.vs
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ repos:
- id: end-of-file-fixer
- id: check-shebang-scripts-are-executable
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.3
rev: v19.1.4
hooks:
- id: clang-format
types_or: [c++, c]
Expand Down
57 changes: 51 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# SPDX-License-Identifier: BSD-3-Clause
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Make sure users don't get warnings on a tested (3.0 to 3.27) version of CMake. For
# Make sure users don't get warnings on a tested (3.0 to 3.31) version of CMake. For
# most of the policies, the new version is better (hence the change). We don't use the
# 3.0...3.17 syntax because of a bug in an older MSVC's built-in and modified CMake 3.11
if(${CMAKE_VERSION} VERSION_GREATER 3.20)
cmake_minimum_required(VERSION 3.20...3.30)
if(${CMAKE_VERSION} VERSION_GREATER 3.22)
cmake_minimum_required(VERSION 3.22...3.31)
else()
cmake_minimum_required(VERSION 3.0)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
Expand All @@ -23,7 +23,7 @@ endif()
project(
${UNITS_CMAKE_PROJECT_NAME}
LANGUAGES C CXX
VERSION 0.9.2
VERSION 0.10.0
)
include(CMakeDependentOption)
include(CTest)
Expand Down Expand Up @@ -108,6 +108,11 @@ cmake_dependent_option(
UNITS_CLANG_TIDY "Look for and use Clang-Tidy" OFF
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT CMAKE_VERSION VERSION_LESS 3.6" OFF
)

cmake_dependent_option(
UNITS_BUILD_PYTHON_LIBRARY "Build the simplified python library" OFF
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF
)
set(UNITS_CLANG_TIDY_OPTIONS
""
CACHE STRING "Clang tidy options, such as -fix, semicolon separated"
Expand Down Expand Up @@ -219,12 +224,52 @@ elseif(UNITS_ENABLE_TESTS)
message(WARNING "UNITS unit tests only supported under cmake 3.13 or greater")
endif()

if(NOT UNITS_HEADER_ONLY AND NOT UNITS_BUILD_FUZZ_TARGETS)
if(NOT UNITS_HEADER_ONLY
AND NOT UNITS_BUILD_FUZZ_TARGETS
AND NOT SKBUILD
)
add_subdirectory(webserver)
add_subdirectory(converter)
endif()

if(UNITS_INSTALL)
if(NOT UNITS_HEADER_ONLY AND UNITS_BUILD_PYTHON_LIBRARY)
message(STATUS "building the python library")

find_package(
Python 3.10 REQUIRED
COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule
)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build." FORCE
)
set_property(
CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
"RelWithDebInfo"
)
endif()

# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE nanobind_ROOT
)
find_package(nanobind CONFIG REQUIRED)

nanobind_add_module(units_llnl_ext NB_STATIC STABLE_ABI python/units_python.cpp)

target_link_libraries(units_llnl_ext PRIVATE units::units)

# Install directive for scikit-build-core
install(TARGETS units_llnl_ext LIBRARY DESTINATION units_llnl)

endif()

if(UNITS_INSTALL AND NOT SKBUILD)
if(UNITS_BUILD_STATIC_LIBRARY)
install(TARGETS compile_flags_target ${UNITS_LIBRARY_EXPORT_COMMAND})
endif()
Expand Down
Loading
Loading