Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ post_commit_hooks = []
filename = "CMakeLists.txt"

[[tool.bumpversion.files]]
filename = "src/serialbox-python/setup.py"
filename = "pyproject.toml"

[[tool.bumpversion.files]]
filename = "src/serialbox-python/serialbox/__init__.py"
2 changes: 1 addition & 1 deletion .github/workflows/pip_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: pip install -r src/serialbox-python/requirements.txt

- name: build
run: pip install src/serialbox-python
run: pip install .

- name: run tests
run: pytest -v test/serialbox-python/serialbox >> $GITHUB_STEP_SUMMARY
123 changes: 123 additions & 0 deletions .github/workflows/pypi_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Deploy Python Distribution

on: [push, pull_request]

jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install boost
run: |
sudo apt-get update
sudo apt-get install libboost-dev
- name: Install pypa/build
run: |
python -m pip install build --user
- name: Build source tarball
run: |
python -m build --sdist --outdir dist/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: sdist
path: ./dist/**

build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-13 # intel
- macos-14 # apple silicon
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_SKIP: pp* *musllinux* cp36-* cp37-*
CIBW_BEFORE_BUILD_LINUX: yum -y install boost-devel
CIBW_ARCHS_LINUX: "x86_64"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_BEFORE_BUILD_MACOS: brew install boost # should be ok as we only use headers
MACOSX_DEPLOYMENT_TARGET: 10.15
with:
output-dir: dist

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./dist/*.whl

test_wheels:
name: Test wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: [build_wheels]
strategy:
matrix:
os:
- ubuntu-latest
- macos-13 # intel
- macos-14 # apple silicon
steps:
- name: Download wheel
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Test wheel
run: |
python -m venv .venv
. .venv/bin/activate
python -m pip install --find-links ./dist serialbox4py
python -c "from serialbox import *"

# publish-pypi:
# name: Publish Python distribution to pypi.org
# runs-on: ubuntu-latest
# needs: [build_wheels, build_sdist]
# if: ${{ github.event_name == 'workflow-dispatch' }}
# environment:
# name: pypi
# url: https://pypi.org/project/serialbox4py/
# permissions:
# id-token: write
# steps:
# - name: Download wheel
# uses: actions/download-artifact@v4
# with:
# path: dist
# merge-multiple: true
# - name: Publish distribution to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# repository-url: https://pypi.org/legacy/

publish-test-pypi:
name: Publish Python distribution to test.pypi.org
runs-on: ubuntu-latest
needs: [build_wheels, build_sdist]
if: ${{ github.event_name == 'workflow_dispatch' }} # TODO: once working, enable line below
# if: ${{ github.event_name == 'release' }} # triggered by releasing on github, test first before manually triggering the deployment to PyPI (see release documentation)
environment:
name: testpypi
url: https://test.pypi.org/project/serialbox4py/
permissions:
id-token: write
steps:
- name: Download wheel
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Publish distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "CMake

cmake_policy(SET CMP0048 NEW)
cmake_minimum_required(VERSION 3.12.0)
# note: version should not be changed manually, use bump-my-version instead:
# install: pip install bump-my-version
# example: bump-my-version bump patch
project(Serialbox LANGUAGES C CXX VERSION 2.6.2)

set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -142,8 +145,15 @@ if(SERIALBOX_BUILD_SHARED)
# The RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
if(SKBUILD_PROJECT_NAME)
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
endif()
endif()

if(NOT(SERIALBOX_LOGGING))
Expand Down
18 changes: 13 additions & 5 deletions cmake/modules/SerialboxInstallTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ function( serialbox_install_targets )

foreach( target ${target_list} )
if( TARGET ${target} )
install(TARGETS ${target}
EXPORT SerialboxTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
if(SKBUILD_PROJECT_NAME)
install(TARGETS ${target}
EXPORT SerialboxTargets
LIBRARY DESTINATION .
ARCHIVE DESTINATION .
)
else()
install(TARGETS ${target}
EXPORT SerialboxTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
export( TARGETS ${target}
APPEND FILE ${PROJECT_BINARY_DIR}/SerialboxTargets.cmake
NAMESPACE Serialbox::
Expand Down
67 changes: 67 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[build-system]
build-backend = 'scikit_build_core.build'
requires = [
'cmake>=3.25',
'numpy >= 1.23',
'scikit-build-core>=0.10.7',
'wheel>=0.45.1',
]

[project]
dependencies = [
'numpy>=1.23',
'packaging>=20.0'
]

description = 'Serialbox - Serialization Library for C, C++, Fortran and Python'
name = 'serialbox4py'
# note: version should not be changed manually, use bump-my-version instead:
# install: pip install bump-my-version
# example: bump-my-version bump patch
version = '2.6.2'
license = {text = "BSD-3 License"}
readme = {file = 'README.md', content-type = 'text/markdown'}
authors = [{email = '[email protected]'}, {name = 'ETH Zurich'}]
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: File Formats',
'Topic :: Scientific/Engineering :: Atmospheric Science',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Software Development :: Testing',
'Topic :: System :: Archiving'
]

[project.urls]
repository = 'https://github.com/GridTools/serialbox'

[project.optional-dependencies]
test = ['pytest', 'pytest-cache']

[tool.scikit-build]
minimum-version = '0.5'
cmake.minimum-version = '3.25'
cmake.verbose = true
cmake.source-dir = "."
cmake.build-type = "Release"
cmake.args = [
"-DSERIALBOX_ENABLE_FORTRAN=false",
"-DSERIALBOX_ENABLE_SDB=false",
"-DSERIALBOX_ASYNC_API=false"
]
wheel.expand-macos-universal-tags = true
wheel.install-dir = "serialbox"
wheel.packages = []
wheel.license-files = []
11 changes: 9 additions & 2 deletions src/serialbox-python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ if(SERIALBOX_ENABLE_PYTHON)
add_dependencies(SerialboxCShared SerialboxPython)

# Install python source
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/serialbox-python/serialbox/
if(SKBUILD_PROJECT_NAME)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/serialbox-python/serialbox/
DESTINATION .
FILES_MATCHING PATTERN "*.py"
PATTERN "*__pycache__*" EXCLUDE)
else()
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/serialbox-python/serialbox/
DESTINATION python/serialbox
FILES_MATCHING PATTERN "*.py"
PATTERN "*__pycache__*" EXCLUDE)

endif()

install(CODE "
EXECUTE_PROCESS(COMMAND
ln -sf
Expand Down
1 change: 0 additions & 1 deletion src/serialbox-python/MANIFEST.in

This file was deleted.

3 changes: 0 additions & 3 deletions src/serialbox-python/pyproject.toml

This file was deleted.

29 changes: 23 additions & 6 deletions src/serialbox-python/serialbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##
## S E R I A L B O X
##
## This file is distributed under terms of BSD license.
## This file is distributed under terms of BSD license.
## See LICENSE.txt for more information.
##
##===------------------------------------------------------------------------------------------===##
Expand All @@ -15,8 +15,13 @@

"""'Serialbox Python Interface'"""

__versioninfo__ = (2, 2, 0)
__version__ = '.'.join(str(v) for v in __versioninfo__)
from packaging import version as pkg_version

# note: version should not be changed manually, use bump-my-version instead:
# install: pip install bump-my-version
# example: bump-my-version bump patch
__version__ = "2.6.2"
__versioninfo__ = pkg_version.parse(__version__)

#
# Check python version
Expand All @@ -31,6 +36,7 @@
#
try:
import numpy

del numpy
except ImportError:
raise Exception("Serialbox requires numpy")
Expand All @@ -49,6 +55,17 @@
from .archive import Archive
from .slice import Slice

__all__ = ['Config', 'TypeID', 'SerialboxError', 'Logging', 'Serializer', 'Savepoint',
'SavepointCollection', 'MetainfoMap', 'FieldMetainfo', 'OpenModeKind', 'Archive',
'Slice']
__all__ = [
"Config",
"TypeID",
"SerialboxError",
"Logging",
"Serializer",
"Savepoint",
"SavepointCollection",
"MetainfoMap",
"FieldMetainfo",
"OpenModeKind",
"Archive",
"Slice",
]
Loading
Loading