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: 0 additions & 5 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ jobs:
with:
version: "0.7.21"

- name: Install libnsl2
run: |
sudo apt-get update
sudo apt-get install -y libnsl2

- name: Build package
run: uv build --wheel

Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

# this is installed by default on Ubuntu 22.04
- name: Install libnsl2 (Linux only)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libnsl2

- name: Install the project
run: uv sync

Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/test_mikeio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install libnsl2 (Linux only)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libnsl2

- name: Install MIKE IO
working-directory: mikeio
run: uv sync --group test --no-dev
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- On Linux, mikecore no longer needs `libnsl2` installed, which Ubuntu 24.04
doesn't install by default. The bundled Xerces library was linked against it
without using it
([#59](https://github.com/DHI/mikecore-python/issues/59)).
- `DfsuFile` opens dfsu files from MIKE 2027 with a submesh type, such as 3D
files and locally refined meshes, which raised "not a valid dfsu file".
Files from later MIKE versions with more custom block values also open.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ installed. With another library in the process that loads MIKE Core

To share one set instead, set `MIKECORE_PYTHON_BIN` to the installation's `bin`
folder (on Windows, the 64-bit `bin\x64`) before mikecore is first imported. On
Linux, you may also need that folder on `LD_LIBRARY_PATH`. mikecore is only
tested with its bundled libraries.
Linux, you may also need that folder on `LD_LIBRARY_PATH`, and on Ubuntu 24.04
the installation's libraries may need `sudo apt install libnsl2`. mikecore is
only tested with its bundled libraries.

Either way, mikecore's EUM items and units match the bundled version. With
MIKE Core from a newer version, EUM lookups can raise `ValueError`
Expand Down
11 changes: 9 additions & 2 deletions buildUtil/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,20 @@ def read_packages_config(filepath: str | Path) -> tuple[str, list[tuple[str, str
# patching their imports would invalidate DHI's signature (ADR 0002).
LIB_TAG = "-mikecore-python"

# Linked but unused: Xerces imports no symbols from libnsl, and Ubuntu 24.04
# doesn't install it by default (#59).
UNUSED_NEEDED = ["libnsl.so.2"]


def tagged(name: str) -> str:
"""libintlc.so.5 -> libintlc-mikecore-python.so.5"""
return name.replace(".so", LIB_TAG + ".so", 1)


def isolate_linux_libs(bin_folder: str | Path):
"""Unique names (#45), and DT_RPATH rather than DT_RUNPATH so
LD_LIBRARY_PATH can't override $ORIGIN."""
"""Unique names (#45), DT_RPATH rather than DT_RUNPATH so
LD_LIBRARY_PATH can't override $ORIGIN, and no unused system
dependencies (#59)."""
patchelf_path = shutil.which("patchelf")
libs = list(Path(bin_folder).glob("*.so*"))
renames = {so.name: tagged(so.name) for so in libs}
Expand All @@ -123,6 +128,8 @@ def isolate_linux_libs(bin_folder: str | Path):
]
for old, new in renames.items():
args += ["--replace-needed", old, new]
for name in UNUSED_NEEDED:
args += ["--remove-needed", name]
subprocess.run(args + [str(so.absolute())], check=True)
so.replace(so.with_name(new_name))

Expand Down
13 changes: 13 additions & 0 deletions tests/test_installation_bin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ctypes
import os
import shutil
import subprocess
Expand Down Expand Up @@ -47,11 +48,23 @@ def installation_bin(tmp_path: Path) -> Path:
natives = list(PACKAGES.glob(f"*/runtimes/{RUNTIME}/native"))
if not natives:
pytest.skip("needs the NuGet packages that building a checkout downloads")
if os.name != "nt" and not loadable("libnsl.so.2"):
# The bundled copy has this dependency removed (#59); an
# installation's Xerces still has it.
pytest.skip("the installation's Xerces needs libnsl2")
for native in natives:
shutil.copytree(native, tmp_path, dirs_exist_ok=True)
return tmp_path


def loadable(library: str) -> bool:
try:
ctypes.CDLL(library)
except OSError:
return False
return True


def test_installation_libraries_read_like_the_bundled_ones(installation_bin):
mikebin, *results = run_read(installation_bin)

Expand Down
Loading