From 6e0753679482e9c5c33a2b3fc2d6c52485ae3ba6 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:45:58 +0200 Subject: [PATCH] Remove global_statics and unused fixture Global_statics was mainly used in versions of parcels with c compilation --- parcels/tools/__init__.py | 1 - parcels/tools/global_statics.py | 42 --------------------------------- tests/test_kernel_execution.py | 15 ------------ 3 files changed, 58 deletions(-) delete mode 100644 parcels/tools/global_statics.py diff --git a/parcels/tools/__init__.py b/parcels/tools/__init__.py index 5a735ed003..6909c6fb44 100644 --- a/parcels/tools/__init__.py +++ b/parcels/tools/__init__.py @@ -1,6 +1,5 @@ from .converters import * from .exampledata_utils import * -from .global_statics import * from .interpolation_utils import * from .loggers import * from .statuscodes import * diff --git a/parcels/tools/global_statics.py b/parcels/tools/global_statics.py deleted file mode 100644 index 317848786b..0000000000 --- a/parcels/tools/global_statics.py +++ /dev/null @@ -1,42 +0,0 @@ -import _ctypes -import os -import sys -from pathlib import Path -from tempfile import gettempdir -from typing import Literal - -USER_ID: int | Literal["tmp"] -try: - from os import getuid - - USER_ID = getuid() -except: - # Windows does not have getuid() - USER_ID = "tmp" - - -__all__ = ["cleanup_remove_files", "cleanup_unload_lib", "get_cache_dir", "get_package_dir"] - - -def cleanup_remove_files(lib_file, log_file): - if os.path.isfile(lib_file): - [os.remove(s) for s in [lib_file, log_file]] - - -def cleanup_unload_lib(lib): - # Clean-up the in-memory dynamic linked libraries. - # This is not really necessary, as these programs are not that large, but with the new random - # naming scheme which is required on Windows OS'es to deal with updates to a Parcels' kernel. - if lib is not None: - _ctypes.FreeLibrary(lib._handle) if sys.platform == "win32" else _ctypes.dlclose(lib._handle) - - -def get_package_dir(): - fpath = Path(__file__) - return fpath.parent.parent - - -def get_cache_dir(): - directory = os.path.join(gettempdir(), f"parcels-{USER_ID}") - Path(directory).mkdir(exist_ok=True) - return directory diff --git a/tests/test_kernel_execution.py b/tests/test_kernel_execution.py index 8de32ed963..f3a8fd444f 100644 --- a/tests/test_kernel_execution.py +++ b/tests/test_kernel_execution.py @@ -1,9 +1,6 @@ -import uuid - import numpy as np import pytest -import parcels from parcels import ( AdvectionRK4, FieldOutOfBoundError, @@ -16,18 +13,6 @@ from tests.utils import create_fieldset_unit_mesh -@pytest.fixture() -def parcels_cache(monkeypatch, tmp_path_factory): - """Dedicated folder parcels used to store cached Kernel C code/libraries and log files.""" - tmp_path = tmp_path_factory.mktemp(f"c-code-{uuid.uuid4()}") - - def fake_get_cache_dir(): - return tmp_path - - monkeypatch.setattr(parcels.kernel, "get_cache_dir", fake_get_cache_dir) - yield tmp_path - - @pytest.fixture def fieldset_unit_mesh(): return create_fieldset_unit_mesh()