Skip to content

Commit

Permalink
python313Packages.segyio: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot-wxt1221 committed Jan 11, 2025
1 parent 48d5c5f commit 925fdc8
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkgs/development/python-modules/segyio/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ buildPythonPackage rec {
patches = [
# https://github.com/equinor/segyio/pull/570
./add_missing_cstdint.patch
# https://github.com/equinor/segyio/pull/576/
./fix-setuptools.patch
./explicitly-cast.patch
./numpy-2.patch
];

postPatch = ''
Expand Down Expand Up @@ -49,10 +53,10 @@ buildPythonPackage rec {
numpy
];

meta = with lib; {
meta = {
description = "Fast Python library for SEGY files";
homepage = "https://github.com/equinor/segyio";
license = licenses.lgpl3Only;
maintainers = with maintainers; [ atila ];
license = lib.licenses.lgpl3Only;
maintainers = with lib.maintainers; [ atila ];
};
}
32 changes: 32 additions & 0 deletions pkgs/development/python-modules/segyio/explicitly-cast.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From eafe8476566e1d8e8b9a486ca808685cb439a767 Mon Sep 17 00:00:00 2001
From: Sveinung Rundhovde <[email protected]>
Date: Mon, 29 Jul 2024 10:46:35 +0200
Subject: [PATCH] Explicitly cast from BinField to int

Parsing segyio.BinField type as int in PyArg_ParseTuple is no longer
possible.
---
python/segyio/open.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/python/segyio/open.py b/python/segyio/open.py
index cd902c15..80bc3a5b 100644
--- a/python/segyio/open.py
+++ b/python/segyio/open.py
@@ -166,8 +166,8 @@ def open(filename, mode="r", iline = 189,
f = segyio.SegyFile(fd,
filename = str(filename),
mode = mode,
- iline = iline,
- xline = xline,
+ iline = int(iline),
+ xline = int(xline),
endian = endian,
)

@@ -189,4 +189,4 @@ def open(filename, mode="r", iline = 189,
if ignore_geometry:
return f

- return infer_geometry(f, metrics, iline, xline, strict)
+ return infer_geometry(f, metrics, int(iline), int(xline), strict)
32 changes: 32 additions & 0 deletions pkgs/development/python-modules/segyio/fix-setuptools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 6df089258c2ef4356427263f652cff0c053c6173 Mon Sep 17 00:00:00 2001
From: Sveinung Rundhovde <[email protected]>
Date: Fri, 26 Jul 2024 15:03:33 +0200
Subject: [PATCH] Fix attribute error in setup.py

This line was causing a error due to an update to scikit-build. The
issue was that the setuptools.command.test module is not put into the
symbol table by the setuptools import, but it was put there during the
skbuild import causing it to be available. Due to changes in
scikit-build this is no longer the case and the line gives an
AttributError.

The rationale for this line was that scikit-builds test command implied
develop (this was obnoxious), something that is no longer true. There is
thus no longer any reason to keep this line, so we can fix this issue by
simply removing it.
---
python/setup.py | 1 -
1 file changed, 1 deletion(-)

diff --git a/python/setup.py b/python/setup.py
index 6c6553bc..6bae62f0 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -95,7 +95,6 @@ def src(x):
# supported OS X release 10.9
'-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9',
],
- cmdclass = { 'test': setuptools.command.test.test },
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Other Environment',
34 changes: 34 additions & 0 deletions pkgs/development/python-modules/segyio/numpy-2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 75b2156a6414e2464eb15663004b8ab928374135 Mon Sep 17 00:00:00 2001
From: Sveinung Rundhovde <[email protected]>
Date: Tue, 30 Jul 2024 08:32:56 +0200
Subject: [PATCH] Fix test failing due to Numpy 2.0 promotion rules

From Numpy 2.0 adding a numpy.float32 and a Python numeric type returns
a numy.float32 when it previously returned a numpy.float64. This changes
the behavior when using the Python builtin sum function on a
numpy.float32 array as the internal computations now will be performed
as numpy.float32 additions when it used to be numpy.float64.

Passing a numpy.double(0) as a start value to the innermost sum forces
the old behavior and provides consistent results for Numpy 1 and 2.
---
python/test/segyio_c.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/test/segyio_c.py b/python/test/segyio_c.py
index 45fe95d89..b1e144d9d 100644
--- a/python/test/segyio_c.py
+++ b/python/test/segyio_c.py
@@ -540,10 +540,10 @@ def read_line(f, metrics, iline_idx, xline_idx):
buf = numpy.zeros((len(iline_idx), samples), dtype=numpy.single)

f.getline(xline_trace0, len(iline_idx), xline_stride, offsets, buf)
- assert sum(sum(buf)) == approx(800.061169624, abs=1e-6)
+ assert sum(sum(buf), numpy.double(0)) == approx(800.061169624, abs=1e-6)

f.getline(iline_trace0, len(xline_idx), iline_stride, offsets, buf)
- assert sum(sum(buf)) == approx(305.061146736, abs=1e-6)
+ assert sum(sum(buf), numpy.double(0)) == approx(305.061146736, abs=1e-6)

f.close()

0 comments on commit 925fdc8

Please sign in to comment.