ncv 0.3.2__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {ncv-0.3.2 → ncv-0.3.4}/PKG-INFO +22 -1
  2. {ncv-0.3.2 → ncv-0.3.4}/README.md +21 -0
  3. {ncv-0.3.2 → ncv-0.3.4}/ncv/app.py +3 -2
  4. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvcommon.py +45 -3
  5. ncv-0.3.4/ncv/qt_compat.py +56 -0
  6. {ncv-0.3.2 → ncv-0.3.4}/ncv.egg-info/PKG-INFO +22 -1
  7. {ncv-0.3.2 → ncv-0.3.4}/pyproject.toml +1 -1
  8. {ncv-0.3.2 → ncv-0.3.4}/tests/test_session_qt.py +64 -1
  9. ncv-0.3.2/ncv/qt_compat.py +0 -38
  10. {ncv-0.3.2 → ncv-0.3.4}/LICENSE +0 -0
  11. {ncv-0.3.2 → ncv-0.3.4}/ncv/__init__.py +0 -0
  12. {ncv-0.3.2 → ncv-0.3.4}/ncv/__main__.py +0 -0
  13. {ncv-0.3.2 → ncv-0.3.4}/ncv/dimensions.py +0 -0
  14. {ncv-0.3.2 → ncv-0.3.4}/ncv/images/ncvue_icon.ico +0 -0
  15. {ncv-0.3.2 → ncv-0.3.4}/ncv/images/ncvue_icon.png +0 -0
  16. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvcontour.py +0 -0
  17. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvmap.py +0 -0
  18. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvmatrix.py +0 -0
  19. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvmethods.py +0 -0
  20. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvscatter.py +0 -0
  21. {ncv-0.3.2 → ncv-0.3.4}/ncv/ncvutils.py +0 -0
  22. {ncv-0.3.2 → ncv-0.3.4}/ncv/session.py +0 -0
  23. {ncv-0.3.2 → ncv-0.3.4}/ncv/ui/contour_panel.ui +0 -0
  24. {ncv-0.3.2 → ncv-0.3.4}/ncv/ui/main_window.ui +0 -0
  25. {ncv-0.3.2 → ncv-0.3.4}/ncv/ui/map_panel.ui +0 -0
  26. {ncv-0.3.2 → ncv-0.3.4}/ncv/ui/map_unavailable.ui +0 -0
  27. {ncv-0.3.2 → ncv-0.3.4}/ncv/ui/matrix_panel.ui +0 -0
  28. {ncv-0.3.2 → ncv-0.3.4}/ncv/ui/scatter_panel.ui +0 -0
  29. {ncv-0.3.2 → ncv-0.3.4}/ncv.egg-info/SOURCES.txt +0 -0
  30. {ncv-0.3.2 → ncv-0.3.4}/ncv.egg-info/dependency_links.txt +0 -0
  31. {ncv-0.3.2 → ncv-0.3.4}/ncv.egg-info/entry_points.txt +0 -0
  32. {ncv-0.3.2 → ncv-0.3.4}/ncv.egg-info/requires.txt +0 -0
  33. {ncv-0.3.2 → ncv-0.3.4}/ncv.egg-info/top_level.txt +0 -0
  34. {ncv-0.3.2 → ncv-0.3.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ncv
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: A quick PyQt6 viewer for NetCDF files
5
5
  Author-email: Sanjeev Bashyal <sanjeev.bashyal@ufz.de>
6
6
  License: MIT
@@ -83,6 +83,27 @@ python3 -m pip install --upgrade pip
83
83
  python3 -m pip install ncv
84
84
  ```
85
85
 
86
+ ### Install into a conda environment
87
+
88
+ Install PyQt6 from conda-forge **before** ncv, so pip doesn't fetch the PyQt6
89
+ wheel. That wheel's Qt libraries only search their own folder for system
90
+ libraries, so in a conda environment they can mix the system's older FreeType
91
+ with conda's newer HarfBuzz and fail with
92
+ `undefined symbol: FT_Get_Colorline_Stops`.
93
+
94
+ ```bash
95
+ conda install -c conda-forge pyqt6 # conda-forge "pyqt" is PyQt5
96
+ python3 -m pip install ncv
97
+ ```
98
+
99
+ If the wheel is already installed, swap it out (pip first, as both write to
100
+ `site-packages/PyQt6`):
101
+
102
+ ```bash
103
+ pip uninstall -y PyQt6 PyQt6-Qt6 PyQt6-sip
104
+ conda install -c conda-forge pyqt6
105
+ ```
106
+
86
107
  ### Install as an isolated application with pipx
87
108
 
88
109
  If `pipx` is available, it can keep the application separate from other
@@ -62,6 +62,27 @@ python3 -m pip install --upgrade pip
62
62
  python3 -m pip install ncv
63
63
  ```
64
64
 
65
+ ### Install into a conda environment
66
+
67
+ Install PyQt6 from conda-forge **before** ncv, so pip doesn't fetch the PyQt6
68
+ wheel. That wheel's Qt libraries only search their own folder for system
69
+ libraries, so in a conda environment they can mix the system's older FreeType
70
+ with conda's newer HarfBuzz and fail with
71
+ `undefined symbol: FT_Get_Colorline_Stops`.
72
+
73
+ ```bash
74
+ conda install -c conda-forge pyqt6 # conda-forge "pyqt" is PyQt5
75
+ python3 -m pip install ncv
76
+ ```
77
+
78
+ If the wheel is already installed, swap it out (pip first, as both write to
79
+ `site-packages/PyQt6`):
80
+
81
+ ```bash
82
+ pip uninstall -y PyQt6 PyQt6-Qt6 PyQt6-sip
83
+ conda install -c conda-forge pyqt6
84
+ ```
85
+
65
86
  ### Install as an isolated application with pipx
66
87
 
67
88
  If `pipx` is available, it can keep the application separate from other
@@ -5,6 +5,9 @@ import sys
5
5
 
6
6
  import numpy as np
7
7
 
8
+ from .qt_compat import QtGui, QtWidgets, require_qt
9
+ require_qt()
10
+
8
11
  from . import ncvmap as _ncvmap
9
12
  from .ncvcommon import load_ui, resource_path
10
13
  from .ncvcontour import ContourPanel
@@ -12,7 +15,6 @@ from .ncvmap import MapPanel, MapUnavailablePanel
12
15
  from .ncvmatrix import MatrixPanel
13
16
  from .ncvscatter import ScatterPanel
14
17
  from .ncvutils import selvar, vardim2var
15
- from .qt_compat import QtGui, QtWidgets, require_qt
16
18
  from .session import HAVE_XARRAY, NcvSession, normalize_files
17
19
 
18
20
 
@@ -181,7 +183,6 @@ class NcvMainWindow(QtWidgets.QMainWindow):
181
183
 
182
184
  def ncv(ncfile=None, miss=None, usex=False):
183
185
  """Launch the Qt ncv application."""
184
- require_qt()
185
186
  if miss is None:
186
187
  miss = np.nan
187
188
  app = QtWidgets.QApplication.instance()
@@ -35,6 +35,8 @@ __all__ = [
35
35
  "cursor_label",
36
36
  "float_or_none",
37
37
  "load_ui",
38
+ "CHUNK_MAX_CELLS",
39
+ "cgroup_available",
38
40
  "memory_budget_cells",
39
41
  "native_levels",
40
42
  "set_no_data_colors",
@@ -45,12 +47,48 @@ __all__ = [
45
47
  ]
46
48
 
47
49
 
50
+ # Chunk size that keeps a switch under ~0.5 s (about 9 ns per cell measured on
51
+ # Contour and Matrix). Beyond this, more memory only buys slower switches.
52
+ CHUNK_MAX_CELLS = 36_000_000
53
+
54
+
55
+ def cgroup_available(root="/sys/fs/cgroup", proc="/proc/self/cgroup"):
56
+ """Bytes left under this process's tightest cgroup v2 ``memory.max``.
57
+
58
+ HPC login nodes and batch jobs cap each user well below the node's RAM,
59
+ which is all ``/proc/meminfo`` reports. None when unlimited or unknown.
60
+ """
61
+ try:
62
+ with open(proc) as cgroups:
63
+ path = next(line.split("::", 1)[1].strip()
64
+ for line in cgroups if line.startswith("0::"))
65
+ except (OSError, StopIteration):
66
+ return None
67
+ left = None
68
+ folder = os.path.join(root, path.lstrip("/"))
69
+ while True:
70
+ try:
71
+ with open(os.path.join(folder, "memory.max")) as limit:
72
+ cap = limit.read().strip()
73
+ if cap != "max":
74
+ with open(os.path.join(folder, "memory.current")) as used:
75
+ room = int(cap) - int(used.read())
76
+ left = room if left is None else min(left, room)
77
+ except (OSError, ValueError):
78
+ pass
79
+ if os.path.abspath(folder) == os.path.abspath(root):
80
+ return None if left is None else max(0, left)
81
+ folder = os.path.dirname(folder)
82
+
83
+
48
84
  def memory_budget_cells(fraction=0.2, bytes_per_cell=32):
49
- """Cells that may be held at once: a fraction of currently available RAM.
85
+ """Cells that may be held at once: a fraction of currently available RAM,
86
+ capped at ``CHUNK_MAX_CELLS``.
50
87
 
51
88
  32 bytes per cell covers the float64 read, the clamp copy and pyqtgraph's
52
89
  RGBA image. Linux reports MemAvailable, which counts reclaimable cache;
53
- other POSIX systems fall back to free pages; anything else to 1 GB.
90
+ other POSIX systems fall back to free pages; anything else to 1 GB. A
91
+ cgroup memory limit (HPC login node or job) lowers it further.
54
92
  """
55
93
  available = None
56
94
  try:
@@ -67,7 +105,11 @@ def memory_budget_cells(fraction=0.2, bytes_per_cell=32):
67
105
  * os.sysconf("SC_PAGE_SIZE"))
68
106
  except (AttributeError, ValueError, OSError):
69
107
  available = 1 << 30
70
- return max(1, int(available * fraction / bytes_per_cell))
108
+ limit = cgroup_available()
109
+ if limit is not None:
110
+ available = min(available, limit)
111
+ return max(1, min(CHUNK_MAX_CELLS,
112
+ int(available * fraction / bytes_per_cell)))
71
113
 
72
114
 
73
115
  def display_axes(dim_values):
@@ -0,0 +1,56 @@
1
+ """PyQt6 and pyqtgraph imports used by ncv."""
2
+ from __future__ import annotations
3
+
4
+ try:
5
+ from PyQt6 import QtCore, QtGui, QtWidgets, uic
6
+ import pyqtgraph as pg
7
+
8
+ QT_AVAILABLE = True
9
+ # ImportError, not ModuleNotFoundError: a mismatched system library (conda
10
+ # mixing pip PyQt6 with its own libfreetype/libharfbuzz) raises a bare
11
+ # ImportError from the C loader, which used to escape as a raw traceback.
12
+ except ImportError as exc: # pragma: no cover - environment specific
13
+ QtCore = QtGui = QtWidgets = uic = pg = None
14
+ QT_AVAILABLE = False
15
+ QT_IMPORT_ERROR = exc
16
+ else:
17
+ QT_IMPORT_ERROR = None
18
+ pg.setConfigOptions(antialias=True, imageAxisOrder="row-major",
19
+ background="w", foreground="k")
20
+
21
+
22
+ def require_qt() -> None:
23
+ if QT_AVAILABLE:
24
+ return
25
+ message = [
26
+ "ncv requires PyQt6 and pyqtgraph to run the Qt viewer.",
27
+ f"Import failed with: {QT_IMPORT_ERROR}",
28
+ ]
29
+ # Both fixes take Qt from conda-forge. Its package is `pyqt6`: conda-forge
30
+ # `pyqt` is PyQt5. pip goes first, as both write to site-packages/PyQt6.
31
+ use_conda_qt = [
32
+ " pip uninstall -y PyQt6 PyQt6-Qt6 PyQt6-sip",
33
+ " conda install -c conda-forge pyqt6",
34
+ ]
35
+ if "undefined symbol" in str(QT_IMPORT_ERROR):
36
+ message += [
37
+ "",
38
+ "That is a library mismatch, not a missing package. Typically the",
39
+ "pip PyQt6 wheel (its Qt libraries search only their own folder,",
40
+ "RUNPATH=$ORIGIN) picks up the system's older libfreetype, while",
41
+ "conda supplies a newer libharfbuzz that needs symbols the old",
42
+ "FreeType lacks. Updating conda's freetype/harfbuzz does not help;",
43
+ "use Qt from conda-forge instead of the pip wheel:",
44
+ *use_conda_qt,
45
+ "or, keeping the wheel, preload conda's FreeType:",
46
+ " LD_PRELOAD=$CONDA_PREFIX/lib/libfreetype.so.6 ncv FILE.nc",
47
+ ]
48
+ elif "cannot open shared object file" in str(QT_IMPORT_ERROR):
49
+ message += [
50
+ "",
51
+ "A system library Qt needs is missing on this machine (commonly on",
52
+ "HPC nodes). Use Qt from conda-forge, which brings its own libraries:",
53
+ *use_conda_qt,
54
+ "or ask the administrators for the library named above.",
55
+ ]
56
+ raise RuntimeError("\n".join(message)) from QT_IMPORT_ERROR
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ncv
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: A quick PyQt6 viewer for NetCDF files
5
5
  Author-email: Sanjeev Bashyal <sanjeev.bashyal@ufz.de>
6
6
  License: MIT
@@ -83,6 +83,27 @@ python3 -m pip install --upgrade pip
83
83
  python3 -m pip install ncv
84
84
  ```
85
85
 
86
+ ### Install into a conda environment
87
+
88
+ Install PyQt6 from conda-forge **before** ncv, so pip doesn't fetch the PyQt6
89
+ wheel. That wheel's Qt libraries only search their own folder for system
90
+ libraries, so in a conda environment they can mix the system's older FreeType
91
+ with conda's newer HarfBuzz and fail with
92
+ `undefined symbol: FT_Get_Colorline_Stops`.
93
+
94
+ ```bash
95
+ conda install -c conda-forge pyqt6 # conda-forge "pyqt" is PyQt5
96
+ python3 -m pip install ncv
97
+ ```
98
+
99
+ If the wheel is already installed, swap it out (pip first, as both write to
100
+ `site-packages/PyQt6`):
101
+
102
+ ```bash
103
+ pip uninstall -y PyQt6 PyQt6-Qt6 PyQt6-sip
104
+ conda install -c conda-forge pyqt6
105
+ ```
106
+
86
107
  ### Install as an isolated application with pipx
87
108
 
88
109
  If `pipx` is available, it can keep the application separate from other
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ncv"
7
- version = "0.3.2"
7
+ version = "0.3.4"
8
8
  description = "A quick PyQt6 viewer for NetCDF files"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -712,7 +712,8 @@ def test_memory_budget_and_read_modes(tmp_path, qt_app):
712
712
 
713
713
  budget = memory_budget_cells()
714
714
  assert budget > 0
715
- assert memory_budget_cells(fraction=0.5) > budget
715
+ # scales with memory below the cap
716
+ assert memory_budget_cells(fraction=0.002) > memory_budget_cells(fraction=0.001)
716
717
 
717
718
  path = tmp_path / "grid.nc"
718
719
  with nc.Dataset(path, "w") as ds:
@@ -1242,6 +1243,68 @@ def test_metadata_toggle_restores_width(qt_app):
1242
1243
  qt_app.processEvents()
1243
1244
  assert panel._header_splitter.sizes() == chosen
1244
1245
 
1246
+ @pytest.mark.parametrize("error, reason, advice", [
1247
+ # an HPC node without Qt's system libraries
1248
+ ("libEGL.so.1: cannot open shared object file", "libEGL.so.1",
1249
+ "conda install -c conda-forge pyqt6"),
1250
+ # pip PyQt6 wheel + system FreeType 2.10 + conda HarfBuzz
1251
+ ("libharfbuzz.so.0: undefined symbol: FT_Get_Colorline_Stops",
1252
+ "FT_Get_Colorline_Stops", "LD_PRELOAD=$CONDA_PREFIX/lib/libfreetype.so.6"),
1253
+ ])
1254
+ def test_broken_pyqt6_reports_the_real_reason(error, reason, advice):
1255
+ code = """
1256
+ import builtins, sys
1257
+ real_import = builtins.__import__
1258
+ def blocked(name, *args, **kwargs):
1259
+ if name.startswith("PyQt6"):
1260
+ raise ImportError(%r)
1261
+ return real_import(name, *args, **kwargs)
1262
+ builtins.__import__ = blocked
1263
+ import ncv # the package itself stays importable
1264
+ try:
1265
+ import ncv.app
1266
+ except RuntimeError as exc:
1267
+ print("RUNTIME:", exc)
1268
+ except Exception as exc:
1269
+ print("OTHER:", type(exc).__name__, exc)
1270
+ """ % error
1271
+ result = subprocess.run([sys.executable, "-c", code], capture_output=True,
1272
+ text=True, cwd=Path(__file__).parents[1])
1273
+ out = result.stdout
1274
+ assert "RUNTIME: ncv requires PyQt6" in out, out + result.stderr
1275
+ assert reason in out # the real reason
1276
+ assert advice in out
1277
+ assert "pip uninstall -y PyQt6 PyQt6-Qt6 PyQt6-sip" in out
1278
+ assert "conda-forge pyqt\n" not in out # that one is PyQt5
1279
+ assert "NoneType" not in out
1280
+
1281
+
1282
+ def test_chunk_budget_is_capped_and_respects_cgroup(tmp_path, monkeypatch):
1283
+ import ncv.ncvcommon as common
1284
+
1285
+ # plenty of memory: the interactivity cap decides
1286
+ assert common.memory_budget_cells(fraction=1e9) == common.CHUNK_MAX_CELLS
1287
+
1288
+ # an HPC-style cgroup tree: the parent caps 2 GiB, 1 GiB already in use
1289
+ gib = 1 << 30
1290
+ leaf = tmp_path / "user.slice" / "user-1.slice"
1291
+ leaf.mkdir(parents=True)
1292
+ (tmp_path / "user.slice" / "memory.max").write_text(str(2 * gib))
1293
+ (tmp_path / "user.slice" / "memory.current").write_text(str(gib))
1294
+ (leaf / "memory.max").write_text("max") # unlimited level
1295
+ (leaf / "memory.current").write_text("123")
1296
+ proc = tmp_path / "cgroup"
1297
+ proc.write_text("0::/user.slice/user-1.slice\n")
1298
+ assert common.cgroup_available(str(tmp_path), str(proc)) == gib
1299
+
1300
+ # nothing readable -> unknown, today's behaviour
1301
+ assert common.cgroup_available(str(tmp_path), str(tmp_path / "nope")) is None
1302
+
1303
+ # the budget follows the cgroup room, not the node's MemAvailable
1304
+ monkeypatch.setattr(common, "cgroup_available", lambda: gib)
1305
+ assert common.memory_budget_cells() == int(gib * 0.2 / 32)
1306
+
1307
+
1245
1308
  def test_cli_help_uses_ncv_entrypoint():
1246
1309
  result = subprocess.run(
1247
1310
  [sys.executable, "-m", "ncv", "--help"],
@@ -1,38 +0,0 @@
1
- """PyQt6 and pyqtgraph imports used by ncv."""
2
- from __future__ import annotations
3
-
4
- try:
5
- from PyQt6 import QtCore, QtGui, QtWidgets, uic
6
- import pyqtgraph as pg
7
-
8
- QT_AVAILABLE = True
9
- # ImportError, not ModuleNotFoundError: a mismatched system library (conda
10
- # mixing pip PyQt6 with its own libfreetype/libharfbuzz) raises a bare
11
- # ImportError from the C loader, which used to escape as a raw traceback.
12
- except ImportError as exc: # pragma: no cover - environment specific
13
- QtCore = QtGui = QtWidgets = uic = pg = None
14
- QT_AVAILABLE = False
15
- QT_IMPORT_ERROR = exc
16
- else:
17
- QT_IMPORT_ERROR = None
18
- pg.setConfigOptions(antialias=True, imageAxisOrder="row-major",
19
- background="w", foreground="k")
20
-
21
-
22
- def require_qt() -> None:
23
- if QT_AVAILABLE:
24
- return
25
- message = [
26
- "ncv requires PyQt6 and pyqtgraph to run the Qt viewer.",
27
- f"Import failed with: {QT_IMPORT_ERROR}",
28
- ]
29
- if "undefined symbol" in str(QT_IMPORT_ERROR):
30
- message += [
31
- "",
32
- "That is a system-library mismatch, not a missing package -- it "
33
- "usually means a pip-installed PyQt6 is loading conda's older "
34
- "libfreetype/libharfbuzz. Align them from one channel:",
35
- " conda install -c conda-forge freetype harfbuzz",
36
- " conda install -c conda-forge pyqt # or take Qt from conda",
37
- ]
38
- raise RuntimeError("\n".join(message)) from QT_IMPORT_ERROR
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes