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
3 changes: 1 addition & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ target_include_directories(_mir PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINA
target_link_libraries(_mir PRIVATE mir)
target_compile_definitions(_mir PRIVATE NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)

# _mir.so installs at site-packages root (not inside mir/) — matches setup.py Extension("_mir")
install(TARGETS _mir DESTINATION ${MIR_PYTHON_INSTALL_DIR} COMPONENT python)
install(TARGETS _mir DESTINATION ${MIR_PYTHON_INSTALL_DIR}/mir COMPONENT python)
install(FILES
mir/src/mir/__init__.py
mir/src/mir/griddef.py
Expand Down
60 changes: 0 additions & 60 deletions python/mir/build_chain.sh

This file was deleted.

6 changes: 4 additions & 2 deletions python/mir/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ classifiers = [
"Operating System :: MacOS",
"Topic :: Scientific/Engineering",
]
dependencies = ["eckit", "findlibs", "numpy", "pyyaml", "scipy"]
dynamic = ["version"]
# NOTE don't list `dependencies` in this file, use setup.py instead
dynamic = ["version", "dependencies"]


[project.scripts]
mir-weight-matrix-convert = "mir.tools.weight_matrix_convert:main"
Expand All @@ -44,3 +45,4 @@ version = {file = "VERSION"}

[tool.setuptools.packages.find]
where = ["src"]
exclude = ["_mir*"]
Comment thread
tmi marked this conversation as resolved.
38 changes: 38 additions & 0 deletions python/mir/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
from setuptools import setup
import platform
from wheel.bdist_wheel import bdist_wheel
import sys

with open('VERSION', 'r') as fVersion:
version = fVersion.readlines()[0].strip()
install_requires = [
f"mirlib=={version}",
f"eckit=={version}",
"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",
]

# NOTE see ci-utils/wheelmaker/buildscripts/setup_utils, we need to get the right abi compat tag
class bdist_wheel_ext(bdist_wheel):
def get_tag(self):
python, abi, plat = bdist_wheel.get_tag(self)
return python, abi, f"manylinux_2_28_{platform.machine()}"


ext_kwargs = {
"darwin": {},
"linux": {"cmdclass": {"bdist_wheel": bdist_wheel_ext}},
}

setup(
version=version,
package_data={
"": ["*.so"],
},
has_ext_modules=lambda: True,
install_requires=install_requires,
**ext_kwargs[sys.platform],
)
10 changes: 3 additions & 7 deletions python/mir/src/mir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
# does it submit to any jurisdiction.


from ctypes import CDLL

# init section -- ensure libmir.so is loaded, utilizing findlibs instead of relying on rpath
import findlibs

m = findlibs.find("mir")
CDLL(m)
findlibs.load("mir")

from _mir import *
from eckit.geo import Grid
from mir._mir import *

__version__ = version()
__lib_version__ = version()
__git_sha1__ = git_sha1()
4 changes: 3 additions & 1 deletion python/mirlib/buildconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# TODO we duplicate information -- pyproject.toml's `name` and `packages` are derivable from $NAME and must stay consistent

NAME="mir"
CMAKE_PARAMS="-Deckit_ROOT=/tmp/mir/prereqs/eckitlib -Deccodes_ROOT=/tmp/mir/prereqs/eccodeslib -Datlas_ROOT=/tmp/mir/prereqs/atlaslib-ecmwf -DENABLE_ECKIT_GEO=1"
_HERE="$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")"
PYTHON_INSTALL_DIR=$(cd -- "$_HERE/../mir/src" && pwd) # dont use readlink -m here, not macos portable
CMAKE_PARAMS="-Deckit_ROOT=/tmp/mir/prereqs/eckitlib -Deccodes_ROOT=/tmp/mir/prereqs/eccodeslib -Datlas_ROOT=/tmp/mir/prereqs/atlaslib-ecmwf -DENABLE_ECKIT_GEO=1 -DENABLE_PYTHON=1 -DMIR_PYTHON_INSTALL_DIR=$PYTHON_INSTALL_DIR -DPython3_FIND_VIRTUALENV=ONLY"
PYPROJECT_DIR="python/mirlib"
DEPENDENCIES='["eccodeslib", "eckitlib", "atlaslib-ecmwf"]'
7 changes: 7 additions & 0 deletions python/mirlib/pre-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# python bindings are built via cmake, as part of the overall compile.sh action
# this requires numpy present -- but currently the cmake files only check
# numpy presence, dont pip install it on its own. Hence we hack the install here

uv pip install 'numpy>=2.0,<3.0' cython
Loading