Skip to content

Commit

Permalink
Update CI and fix Python builds (#59)
Browse files Browse the repository at this point in the history
* ci test python: bump python version and actions

* maybe fix compile error on MacOS silicon

disable error for now (int vs. long in pointer function signature).

* typo

* try setting flags instead

* set C flag (not Fortran flag)

* set flag on macos arm64 only

* win python build: use flang 5

Like for the conda-forge feedstock: issue with fortran-compiler metapakage?

* python win: try fix flang not found

* try fix flag path

* apply patch from fastscapelib-f2py feedstock
  • Loading branch information
benbovy authored Nov 7, 2024
1 parent b4d13f4 commit 9b34561
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ on:

jobs:
unix:
name: 3.8 (${{ matrix.os }})
name: 3.12 (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'

- name: Install Python dependencies
run: |
Expand All @@ -50,30 +50,35 @@ jobs:
run: python -c "import sys; sys.path.pop(0); import fastscapelib_fortran"

windows:
name: 3.8 (windows-latest)
name: 3.12 (windows-latest)
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.8
python-version: 3.12
miniforge-version: latest

- name: Install dependencies
shell: cmd
run: |
conda create -n test python=3.8 cmake c-compiler fortran-compiler scikit-build pip wheel setuptools numpy
conda create -n test python=3.12 cmake c-compiler flang=5.0 scikit-build pip wheel setuptools numpy
- name: Conda env info
shell: cmd
run: >-
conda activate test &&
echo %CONDA% &&
ls %CONDA%\envs\test\Library\bin
- name: Build and install project
shell: cmd
run: >-
conda activate test &&
ls %CONDA%\envs\test &&
ls %CONDA%\envs\test\Library\bin &&
set FC="C:/Miniconda3/envs/test/Library/bin/flang.exe" &&
set FC=%CONDA%\envs\test\Library\bin\flang.exe &&
python setup.py bdist_wheel --dist-dir="dist" -G "NMake Makefiles" -- -DCMAKE_Fortran_COMPILER:FILEPATH="%FC%" &&
python -m pip install --no-index --find-links="dist" fastscapelib_fortran -vvv
Expand Down
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ set(CMAKE_Fortran_FLAGS_DEBUG
# let F2PY (scikit-build) configure flags for F77 and F90 source
if(NOT SKBUILD)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect} ${ioflags}")
else()
if(APPLE AND MAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
# https://github.com/numpy/numpy/issues/25869 ?
# (seems problematic only on MacOS Mx)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=incompatible-function-pointer-types")
endif()
endif()

# override flags for old-school F77 files
Expand Down Expand Up @@ -147,9 +153,10 @@ if(SKBUILD)
# TODO: remove when https://github.com/scikit-build/scikit-build/pull/495 is merged
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})

find_package(PythonLibs REQUIRED)
find_package(PythonExtensions REQUIRED)
find_package(NumPy REQUIRED)
find_package(F2PY REQUIRED)
find_package(PythonExtensions REQUIRED)

set(F2PY_MODULE_NAME "_fastscapelib_fortran")

Expand All @@ -158,6 +165,16 @@ if(SKBUILD)
INCLUDE_DIRECTORIES ${FASTSCAPELIB_SRC_DIR}
)

if (UNIX)
if (APPLE)
set_target_properties(${F2PY_MODULE_NAME} PROPERTIES
LINK_FLAGS '-Wl,-dylib,-undefined,dynamic_lookup')
else()
set_target_properties(${F2PY_MODULE_NAME} PROPERTIES
LINK_FLAGS '-Wl,--allow-shlib-undefined')
endif()
endif()

python_extension_module(${F2PY_MODULE_NAME})

install(
Expand Down
5 changes: 4 additions & 1 deletion cmake/FindF2PY.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
# case, CMake is not used to find the compiler and configure the associated build system.
#

find_program(F2PY_EXECUTABLE NAMES f2py${PYTHON_VERSION_MAJOR} f2py)
# temporarily disable and force searching the program path through the python numpy module (below)
# (see patch added in https://github.com/conda-forge/fastscapelib-f2py-feedstock/pull/17)
# (see https://github.com/conda-forge/numpy-feedstock/issues/276)
# find_program(F2PY_EXECUTABLE NAMES f2py${PYTHON_VERSION_MAJOR} f2py)

# XXX This is required to support NumPy < v0.15.0. See note in module documentation above.
if(NOT F2PY_EXECUTABLE)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "numpy"]
build-backend = "setuptools.build_meta"

0 comments on commit 9b34561

Please sign in to comment.