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
41 changes: 38 additions & 3 deletions .ci/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,46 @@ cxx-compiler = "clang++-18"
c-compiler = "clang-18"
container = "eccr.ecmwf.int/public-ci-images/ubuntu24.04-clang18"

[[matrix.build.include]]
options = "python"
job-script = "./.ci/runner/python.sh.j2"
[packages.mir-python]
compiler-inputs = ["cxx-compiler"]
allow-stale-deps = true

[[packages.mir-python.deps]]
package = "mir"

[[packages.mir-python.deps]]
repo = "ecmwf/eckit"
package = "eckit-python"
ref = "develop"
compiler-inputs = ["cxx-compiler"]
python-version-input = "python-version"

[matrix.python]
packages = ["mir-python"]
triggers = ["upstream-change", "rebuild-request"]

[matrix.python.defaults]
job-script = "./.ci/runner/mir-python.sh.j2"
build-type = "RelWithDebInfo"
# runs-on = "arc-runner-normal"
runs-on = "ubuntu-latest"
cxx-compiler = "g++-13"
c-compiler = "gcc-13"
container = "eccr.ecmwf.int/public-ci-images/ubuntu24.04-gcc13-gfortran13"
platform = "ubuntu-24.04"

[[matrix.python.include]]
python-version = "3.11"

[[matrix.python.include]]
python-version = "3.12"

[[matrix.python.include]]
python-version = "3.13"

[[matrix.python.include]]
python-version = "3.14"

# HPC off along with the ARC runners (hpc-submit): lanes disabled until they are back.
# [matrix.build-hpc]
# execution = "hpc-atos"
Expand Down
46 changes: 46 additions & 0 deletions .ci/packages/mir-python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-FileCopyrightText: 1996- European Centre for Medium-Range Weather Forecasts (ECMWF)
# SPDX-License-Identifier: Apache-2.0

# The mir Python bindings (PyPI: mir-python) as a wheel, against an installed mir:
# cmake -S .ci/packages/mir-python -B build -DCMAKE_PREFIX_PATH=<mir and its deps>
# `cmake --install` writes the wheel to <prefix>/wheels. Without VERSION_SUFFIX
# (set by the PyPI build) it does not require mirlib.

cmake_minimum_required( VERSION 3.18 FATAL_ERROR )

project( mir-python LANGUAGES CXX )

set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )

find_package( mir REQUIRED )
find_package( Python3 3.11 REQUIRED COMPONENTS Interpreter Development.Module NumPy )

set( _repo "${CMAKE_CURRENT_SOURCE_DIR}/../../.." )
set( _staging "${CMAKE_BINARY_DIR}/wheel-staging" )

file( REMOVE_RECURSE "${_staging}" )
file( COPY "${_repo}/python/mir/" DESTINATION "${_staging}"
PATTERN "tests" EXCLUDE
PATTERN "VERSION" EXCLUDE )
configure_file( "${_repo}/VERSION" "${_staging}/VERSION" COPYONLY )

set( PYTHONEXT_INSTALL_DIR "${_staging}/src" CACHE PATH "Install directory for Python extensions" FORCE )
add_subdirectory( "${_repo}/python" python )

# The extensions reach the staging directory only on install, which runs after the tests.
enable_testing()
add_test( NAME mir-python_stage
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --component python --prefix ${CMAKE_BINARY_DIR}/test-prefix )
add_test( NAME mir-python_pytest
COMMAND ${Python3_EXECUTABLE} -m pytest -vv -p no:cacheprovider --basetemp ${CMAKE_BINARY_DIR}/pytest-tmp "${_repo}/python/mir/tests" )
set_tests_properties( mir-python_stage PROPERTIES FIXTURES_SETUP mir-python_staged )
set_tests_properties( mir-python_pytest PROPERTIES FIXTURES_REQUIRED mir-python_staged
ENVIRONMENT "PYTHONPATH=${_staging}/src" )

install( CODE "
execute_process(
COMMAND \"${Python3_EXECUTABLE}\" -m build --wheel --outdir \"\${CMAKE_INSTALL_PREFIX}/wheels\" \"${_staging}\"
COMMAND_ERROR_IS_FATAL ANY
)
" )
13 changes: 13 additions & 0 deletions .ci/packages/mir-python/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "ci"
}
],
"version": 3
}
17 changes: 17 additions & 0 deletions .ci/runner/mir-python.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{# SPDX-FileCopyrightText: 1996- European Centre for Medium-Range Weather Forecasts (ECMWF)
SPDX-License-Identifier: Apache-2.0 #}
{% extends "ci-infrastructure/cmake-runner.sh.j2" %}
{% block set_environment %}
{% import "ci-infrastructure/python.j2" as py %}
{{ py.get_python_via_uv(python_version) }}
# The eckit bindings come from eckit's CI wheel; PyPI's would bring a second eckit (eckitlib).
dep_wheels=()
IFS=';:' read -ra dep_prefixes <<<"${CMAKE_PREFIX_PATH:-}"
for prefix in ${dep_prefixes[@]+"${dep_prefixes[@]}"}; do
for whl in "$prefix"/wheels/*.whl; do
if [ -e "$whl" ]; then dep_wheels+=("$whl"); fi
done
done
uv pip install build ${dep_wheels[@]+"${dep_wheels[@]}"} -r "$CI_SOURCE_DIR/python/mir/requirements.txt" -r "$CI_SOURCE_DIR/python/mir/setup.py"
CI_SOURCE_DIR="$CI_SOURCE_DIR/.ci/packages/mir-python"
{% endblock %}
9 changes: 0 additions & 9 deletions .ci/runner/python.sh.j2

This file was deleted.

50 changes: 48 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- id: r
uses: ecmwf/ci-infrastructure/actions/resolve-deps@main
with:
matrix: build
matrix: build,python
token: ${{ steps.mint.outputs.token }}
rebuild-missing: 'true'
- name: Wait for the deps of build
Expand Down Expand Up @@ -140,10 +140,56 @@ jobs:
install-path: ${{ steps.build.outputs.install-path }}
artifact-name: ${{ matrix._resolved['own-artifact-name'] }}

python:
needs: [ci-approval, resolve, rebuild-producers, build]
name: python (${{ matrix._resolved['job-name'] }})
runs-on: ${{ matrix['runs-on'] }}
container:
image: ${{ matrix.container || '' }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.resolve.outputs.matrices).python }}
steps:
- name: Announce image
uses: ecmwf/ci-infrastructure/actions/announce-image@main
- id: mint
uses: ecmwf/ci-infrastructure/actions/mint-token@main
with:
client-id: ${{ vars.CI_READER_APP_CLIENT_ID }}
private-key: ${{ secrets.CI_READER_APP_PRIVATE_KEY }}
repositories: atlas,ecbuild,eccodes,eckit,fckit,mir,stack-dependencies
permissions: contents:read actions:read
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Fetch resolved deps
id: deps
uses: ecmwf/ci-infrastructure/actions/fetch-deps@main
with:
deps-json: ${{ toJSON(matrix._resolved.deps) }}
token: ${{ steps.mint.outputs.token }}
- name: Print dependency table
uses: ecmwf/ci-infrastructure/actions/print-dep-table@main
with:
resolved: ${{ toJSON(matrix._resolved) }}
- name: Build
id: build
uses: ecmwf/ci-infrastructure/actions/run-job-script@main
with:
job-script: ${{ matrix.job-script }}
matrix-leg: ${{ toJSON(matrix) }}
package: mir
cmake-prefix-path: ${{ steps.deps.outputs.cmake-prefix-path }}
- name: Publish
uses: ecmwf/ci-infrastructure/actions/publish-artifact@main
with:
install-path: ${{ steps.build.outputs.install-path }}
artifact-name: ${{ matrix._resolved['own-artifact-name'] }}

ci-result:
name: collect results
if: always()
needs: [ci-approval, pre-commit, resolve, build]
needs: [ci-approval, pre-commit, resolve, build, python]
runs-on: ubuntu-latest
permissions:
statuses: write
Expand Down
7 changes: 0 additions & 7 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
"ENABLE_TESTS": "ON"
},
"name": "ci"
},
{
"cacheVariables": {
"ENABLE_PYTHON": "ON"
},
"inherits": "ci",
"name": "python"
}
],
"version": 3
Expand Down
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SPDX-License-Identifier = "Apache-2.0"
# as a bare version string by setup.py and by ecbuild; mir.sublime-project and
# CMakePresets.json are JSON.
[[annotations]]
path = ["VERSION", "mir.sublime-project", "CMakePresets.json"]
path = ["VERSION", "mir.sublime-project", "CMakePresets.json", ".ci/packages/*/CMakePresets.json"]
precedence = "closest"
SPDX-FileCopyrightText = "1996- European Centre for Medium-Range Weather Forecasts (ECMWF)"
SPDX-License-Identifier = "Apache-2.0"
Expand Down
5 changes: 4 additions & 1 deletion python/mir/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 1996- European Centre for Medium-Range Weather Forecasts (ECMWF)
# SPDX-License-Identifier: Apache-2.0

import os
import platform
import sys

Expand All @@ -11,13 +12,15 @@
version = fVersion.readlines()[0].strip()

install_requires = [
f"mirlib=={version}",
"eckit", # NOTE we don't pin here, because mirlib is exactly pinned, which in turn exactly pins eckitlib, which in turn constraints eckit
"findlibs",
"numpy>=2.0,<3.0", # NOTE may need tighter range in case of ABI issues. Dont forget to keep in sync with pre-compile.sh (or cmake files if numpy install refactored)
"scipy",
"pyyaml",
]
# Set by the PyPI build (wheelmaker); other builds use a mir installed alongside.
if os.environ.get("VERSION_SUFFIX"):
install_requires.insert(0, f"mirlib=={version}")


# NOTE see ci-utils/wheelmaker/buildscripts/setup_utils, we need to get the right abi compat tag
Expand Down
22 changes: 22 additions & 0 deletions python/mir/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 1996- European Centre for Medium-Range Weather Forecasts (ECMWF)
# SPDX-License-Identifier: Apache-2.0


import os
import shutil
import tempfile

_cache_path = None


def pytest_configure(config):
"""eckit::geo and mir cache to a temporary directory, not the runtime cache (set before it is resolved, on first use)"""
global _cache_path
_cache_path = tempfile.mkdtemp(prefix="mir_cache.")
os.environ["ECKIT_GEO_CACHE_PATH"] = os.path.join(_cache_path, "eckit-geo")
os.environ["MIR_CACHE_PATH"] = os.path.join(_cache_path, "mir")


def pytest_unconfigure(config):
if _cache_path is not None:
shutil.rmtree(_cache_path, ignore_errors=True)
19 changes: 8 additions & 11 deletions python/mir/tests/test_interpolation_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import numpy as np
import pytest
from eckit.geo import projdb_is_available

import mir

Expand Down Expand Up @@ -52,13 +53,6 @@ def _works(input_grid, output_grid, interpolation) -> bool:
return True


def _has_grid(spec) -> bool:
try:
return len(mir.Grid(spec)) > 0
except RuntimeError:
return False


def _cases():
for input_grid, output_grid, interpolation in product(INPUT, OUTPUT, INTERPOLATIONS):
if reason := SHOULD_WORK.get((input_grid, output_grid, interpolation)):
Expand All @@ -79,7 +73,7 @@ def _interpolate(input_spec, output_spec, interpolation):

@pytest.mark.parametrize("input_grid, output_grid, interpolation, works", list(_cases()))
def test_interpolation_matrix(input_grid, output_grid, interpolation, works):
if "swisslv95" in (input_grid, output_grid) and not _has_grid(INPUT["swisslv95"]):
if "swisslv95" in (input_grid, output_grid) and not projdb_is_available():
pytest.skip("swisslv95 requires PROJ")

if not works and mir.Grid(INPUT[input_grid]) == mir.Grid(OUTPUT[output_grid]):
Expand Down Expand Up @@ -167,7 +161,7 @@ def _contains(a, b) -> bool:

@pytest.mark.parametrize("input_grid, output_grid", REGIONAL_CASES)
def test_interpolation_regional(input_grid, output_grid):
if "swisslv95" in (input_grid, output_grid) and not _has_grid(REGIONAL["swisslv95"]):
if "swisslv95" in (input_grid, output_grid) and not projdb_is_available():
pytest.skip("swisslv95 requires PROJ")

grid = mir.Grid(REGIONAL[output_grid])
Expand All @@ -183,7 +177,7 @@ def test_interpolation_regional(input_grid, output_grid):
# projected output grids are kept as such (not described as unstructured_ll, by coordinates)
@pytest.mark.parametrize("input_grid", ["swisslv95", "regular_ll"])
def test_interpolation_projected_output(input_grid):
if not _has_grid(REGIONAL["swisslv95"]):
if not projdb_is_available():
pytest.skip("swisslv95 requires PROJ")

output = _interpolate(REGIONAL[input_grid], REGIONAL["swisslv95"], "nn")
Expand All @@ -195,7 +189,7 @@ def test_interpolation_projected_output(input_grid):
# output points outside the projected input domain are missing (not projected onto its boundary)
@pytest.mark.parametrize("output_spec, size, missing", [(dict(grid="O320"), 57, 1), (dict(grid=[0.1, 0.1]), 960, 12)])
def test_interpolation_projected_outside(output_spec, size, missing):
if not _has_grid(INPUT["swisslv95"]):
if not projdb_is_available():
pytest.skip("swisslv95 requires PROJ")

output = _interpolate(INPUT["swisslv95"], output_spec, "linear")
Expand All @@ -213,6 +207,9 @@ def test_interpolation_projected_outside(output_spec, size, missing):
],
)
def test_interpolation_matrix_grib(input_grid, output_spec, interpolation, size, missing):
if input_grid == "swisslv95" and not projdb_is_available():
pytest.skip("swisslv95 requires PROJ")

from yaml import dump

# output with missing values introduced by the interpolation (input has none)
Expand Down
Loading