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
137 changes: 76 additions & 61 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,65 @@ jobs:
defaults:
run:
working-directory: ./nrtest-swmm

steps:
- name: Checkout repo
uses: actions/checkout@v5

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

python-version: "3.10"
- name: Build wheel
run: |
pip install wheel
python setup.py bdist_wheel
pip install wheel
python setup.py bdist_wheel

- name: Upload wheel artifact
uses: actions/upload-artifact@v4
with:
name: nrtest-swmm-wheel
path: nrtest-swmm/dist/*.whl


build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./swmm-toolkit
steps:
- name: Checkout repo
uses: actions/checkout@v5
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build sdist
run: |
pip install build
python -m build --sdist --outdir ./dist
- name: Upload sdist artifact
uses: actions/upload-artifact@v4
with:
name: swmm-toolkit-sdist
path: swmm-toolkit/dist/*.tar.gz

build_wheels:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
pyver: [cp39, cp310, cp311, cp312, cp313]

os:
[
ubuntu-24.04,
ubuntu-24.04-arm,
windows-2025,
macos-15-intel,
macos-15,
]
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v5
with:
submodules: true

submodules: true
- name: Build wheels
uses: pypa/cibuildwheel@v3.1.4
with:
Expand All @@ -63,65 +86,57 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: "11.0"
CIBW_TEST_COMMAND: "pytest {package}/tests"
CIBW_BEFORE_TEST: pip install -r {package}/test-requirements.txt
# mac needs ninja to build
CIBW_BEFORE_BUILD_MACOS: brew install ninja
CIBW_ENVIRONMENT_MACOS: |
MACOSX_DEPLOYMENT_TARGET=11.0
# remove system swig (cmake bug doesn't respect python venv)
# https://github.com/swig/swig/issues/2481#issuecomment-1949573105
CIBW_BEFORE_BUILD_LINUX: rm -f $(which swig) && rm -f $(which swig4.0)
# configure cibuildwheel to build native archs ('auto'), and some emulated ones
CIBW_ARCHS_LINUX: x86_64
CIBW_ARCHS_WINDOWS: AMD64
CIBW_ARCHS_MACOS: x86_64 arm64
# only build current supported python: https://devguide.python.org/versions/
# don't build pypy or musllinux to save build time. TODO: find a good way to support those archs
CIBW_BUILD: ${{matrix.pyver}}-*
CIBW_SKIP: cp38-* pp* *-musllinux*
# Will avoid testing on emulated architectures
# Skip trying to test arm64 builds on Intel Macs
CIBW_TEST_SKIP: "*-*linux_{aarch64,ppc64le,s390x} *-macosx_universal2:arm64"
# skip 3.8 and any free threaded variants
CIBW_SKIP: cp38-* cp3??t-*
CIBW_ARCHS: native
CIBW_BUILD_VERBOSITY: 1

- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.pyver }}
name: swmm-toolkit-bdist-${{ matrix.os }}
path: ./wheelhouse/*.whl

build_cross_wheels:
merge_wheels:
name: Consolidate all wheel artifacts
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pyver: [cp39, cp310, cp311, cp312, cp313]

needs:
- build_wheels
- build_sdist
steps:
- name: Checkout repo
uses: actions/checkout@v5
- name: Download all distribution artifacts
uses: actions/download-artifact@v5
with:
submodules: true
path: dist
pattern: swmm-toolkit-*dist*
merge-multiple: true

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
- name: Upload consolidated archive
uses: actions/upload-artifact@v4
with:
platforms: all
name: swmm_toolkit_dist
path: ./dist/*

- name: Build wheels
uses: pypa/cibuildwheel@v3.1.4
with:
package-dir: ./swmm-toolkit
env:
# remove system swig (cmake bug doesn't respect python venv)
# https://github.com/swig/swig/issues/2481#issuecomment-1949573105
CIBW_BEFORE_BUILD_LINUX: rm -f $(which swig) && rm -f $(which swig4.0)
# configure cibuildwheel to build native archs ('auto'), and some emulated ones
CIBW_ARCHS_LINUX: aarch64
# only build current supported python: https://devguide.python.org/versions/
# don't build pypy or musllinux to save build time. TODO: find a good way to support those archs
CIBW_BUILD: ${{matrix.pyver}}-*
CIBW_SKIP: cp-*38 pp* *-musllinux*
CIBW_BUILD_VERBOSITY: 1

- uses: actions/upload-artifact@v4
publish_toolkit:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- merge_wheels
# only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/swmm-toolkit
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v5
with:
name: wheels-linux-aarch64-${{ matrix.pyver }}
path: ./wheelhouse/*.whl
name: swmm_toolkit_dist
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
18 changes: 9 additions & 9 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ jobs:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Build wheel in virtual env
env:
MACOSX_DEPLOYMENT_TARGET: "11.0"
- name: Build wheel
run: |
python -m venv --clear ./build-env
${{matrix.activate}}
python -m pip install -r build-requirements.txt
python setup.py bdist_wheel
deactivate
pip install build
python -m build
- name: Upload Wheel
uses: actions/upload-artifact@v4
with:
name: swmm_toolkit_${{ matrix.os }}
path: ./swmm-toolkit/dist/*.whl

- name: Test wheel
run: |
Expand Down
23 changes: 11 additions & 12 deletions swmm-toolkit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@
# Created: Feb 6, 2020
# Modified Sep 2, 2025
#
# Author: See AUTHORS
# Author: See AUTHORS
#

################################################################################
################## CMAKELISTS FOR SWMM-TOOLKIT PROJECT ###################
################################################################################
# ###############################################################################
# ################# CMAKELISTS FOR SWMM-TOOLKIT PROJECT ###################
# ###############################################################################

cmake_minimum_required (VERSION 4.0.2)
cmake_minimum_required(VERSION 4.0.2)

project(swmm-toolkit
VERSION
0.15.5
0.16.1
)


# Trick here is to perform build in a python virtual environment
set(Python_FIND_VIRTUALENV FIRST)
#set(CMAKE_FIND_DEBUG_MODE TRUE)

# set(CMAKE_FIND_DEBUG_MODE TRUE)
if(NOT MSVC)
find_package (Python3 ${PYTHON_VERSION_STRING} COMPONENTS Interpreter Development.Module REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
else()
find_package (Python3 ${PYTHON_VERSION_STRING} COMPONENTS Interpreter Development REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
endif()
#set(CMAKE_FIND_DEBUG_MODE FALSE)

# set(CMAKE_FIND_DEBUG_MODE FALSE)

# SWIG is a build requirement so needs to be installed first
find_package(SWIG REQUIRED)
cmake_policy(SET CMP0078 NEW)
cmake_policy(SET CMP0086 NEW)
include(${SWIG_USE_FILE})


# Add project subdirectories
add_subdirectory(swmm-solver)

Expand Down
21 changes: 20 additions & 1 deletion swmm-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## Community

[![Discord](https://img.shields.io/badge/Discord-Join%20Chat-7289da?logo=discord&logoColor=white)](https://discord.com/channels/1412143058463756421/1412144907312955532)
[![Discord](https://img.shields.io/badge/Discord-Join%20Chat-7289da?logo=discord&logoColor=white)](https://discord.gg/U8wqxgjt9C)

Join the discussion! We will do everything we can to help you!

Expand All @@ -37,4 +37,23 @@ Run a SWMM simulation.
from swmm.toolkit import solver

solver.run('input_file.inp', 'report_file.rpt', 'output_file.out')

```

## Build From Source

> [!NOTE]
> Since version version 0.16.1, swmm-toolkit by default has been built and published
> using the [python stable ABI](https://docs.python.org/3/c-api/stable.html#stable-abi) for
> python 3.9 onward. Using the stable ABI introduces very minor performance reduction while
> substantially simplifying our release process and compatibility with future python versions.
>
> The commands below show how to build this package with and without using the python stable ABI.

### Build with python stable ABI

` python -m build .`

### Build without python stable ABI

` NO_STABLE_ABI=1 python -m build`
8 changes: 0 additions & 8 deletions swmm-toolkit/build-requirements.txt

This file was deleted.

Loading