Skip to content

Commit

Permalink
Remove deprecated preprocessor function cleanup (#2215)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <[email protected]>
  • Loading branch information
bouweandela and schlunma authored Oct 4, 2023
1 parent 837ce35 commit bd3b9a4
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 120 deletions.
7 changes: 0 additions & 7 deletions esmvalcore/preprocessor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from ._io import (
_get_debug_filename,
_sort_products,
cleanup,
concatenate,
load,
save,
Expand Down Expand Up @@ -188,7 +187,6 @@
'remove_supplementary_variables',
# Save to file
'save',
'cleanup',
]

TIME_PREPROCESSORS = [
Expand Down Expand Up @@ -491,11 +489,6 @@ def save(self):
'save',
input_files=self._input_files,
**self.settings['save'])
if 'cleanup' in self.settings:
preprocess([],
'cleanup',
input_files=self._input_files,
**self.settings['cleanup'])

def close(self):
"""Close the file."""
Expand Down
46 changes: 0 additions & 46 deletions esmvalcore/preprocessor/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import copy
import logging
import os
import shutil
import warnings
from itertools import groupby
from pathlib import Path
from typing import Optional
Expand All @@ -18,7 +16,6 @@
from cf_units import suppress_errors
from iris.cube import CubeList

from esmvalcore.exceptions import ESMValCoreDeprecationWarning
from esmvalcore.iris_helpers import merge_cube_attributes

from .._task import write_ncl_settings
Expand Down Expand Up @@ -143,7 +140,6 @@ def load(
------
ValueError
Cubes are empty.
"""
file = Path(file)
logger.debug("Loading:\n%s", file)
Expand Down Expand Up @@ -349,48 +345,6 @@ def _get_debug_filename(filename, step):
return filename


def cleanup(files, remove=None):
"""Clean up after running the preprocessor.
Warning
-------
.. deprecated:: 2.8.0
This function is no longer used and has been deprecated since
ESMValCore version 2.8.0. It is scheduled for removal in version
2.10.0.
Parameters
----------
files: list of Path
Preprocessor output files (will not be removed if not in `removed`).
remove: list of Path or None, optional (default: None)
Files or directories to remove.
Returns
-------
list of Path
Preprocessor output files.
"""
deprecation_msg = (
"The preprocessor function `cleanup` has been deprecated in "
"ESMValCore version 2.8.0 and is scheduled for removal in version "
"2.10.0."
)
warnings.warn(deprecation_msg, ESMValCoreDeprecationWarning)

if remove is None:
remove = []

for path in remove:
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.isfile(path):
os.remove(path)

return files


def _sort_products(products):
"""Sort preprocessor output files by their order in the recipe."""
return sorted(
Expand Down
48 changes: 0 additions & 48 deletions tests/integration/preprocessor/_io/test_cleanup.py

This file was deleted.

20 changes: 1 addition & 19 deletions tests/unit/preprocessor/test_preprocessor_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_close():


@mock.patch('esmvalcore.preprocessor.preprocess', autospec=True)
def test_save_no_cleanup(mock_preprocess):
def test_save(mock_preprocess):
"""Test ``save``."""
product = mock.create_autospec(PreprocessorFile, instance=True)
product.settings = {'save': {}}
Expand All @@ -162,21 +162,3 @@ def test_save_no_cleanup(mock_preprocess):
mock.sentinel.cubes, 'save', input_files=mock.sentinel.input_files
),
]


@mock.patch('esmvalcore.preprocessor.preprocess', autospec=True)
def test_save_cleanup(mock_preprocess):
"""Test ``save``."""
product = mock.create_autospec(PreprocessorFile, instance=True)
product.settings = {'save': {}, 'cleanup': {}}
product._cubes = mock.sentinel.cubes
product._input_files = mock.sentinel.input_files

PreprocessorFile.save(product)

assert mock_preprocess.mock_calls == [
mock.call(
mock.sentinel.cubes, 'save', input_files=mock.sentinel.input_files
),
mock.call([], 'cleanup', input_files=mock.sentinel.input_files),
]

0 comments on commit bd3b9a4

Please sign in to comment.