Skip to content

Commit

Permalink
Allows relative paths for diagnostic scripts. (#2329)
Browse files Browse the repository at this point in the history
Co-authored-by: Valeriu Predoi <valeriu.predoi@gmail.com>
  • Loading branch information
rbeucher and valeriupredoi authored Nov 25, 2024
1 parent d0bfb58 commit ce8714b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion esmvalcore/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import abc
import contextlib
import datetime
import importlib
import logging
import numbers
import os
Expand Down Expand Up @@ -386,9 +387,24 @@ def _initialize_cmd(self):
"""Create an executable command from script."""
diagnostics_root = DIAGNOSTICS.scripts
script = self.script
script_file = (diagnostics_root / Path(script).expanduser()).absolute()

# Check if local diagnostic path exists
script_file = Path(script).expanduser().absolute()
err_msg = f"Cannot execute script '{script}' ({script_file})"
if not script_file.is_file():
logger.info(
"No local diagnostic script found. Attempting to load the script from the base repository."
)
# Check if esmvaltool package is available
if importlib.util.find_spec("esmvaltool") is None:
logger.warning(
"The 'esmvaltool' package cannot be found. Please ensure it is installed."
)

# Try diagnostics_root
script_file = (
diagnostics_root / Path(script).expanduser()
).absolute()
if not script_file.is_file():
raise DiagnosticError(f"{err_msg}: file does not exist.")

Expand Down

0 comments on commit ce8714b

Please sign in to comment.