src.shared_diagnostic module¶
-
exception
src.shared_diagnostic.PodRequirementFailure(pod, msg=None)[source]¶ Bases:
ExceptionException raised if POD doesn’t have required resoruces to run.
-
class
src.shared_diagnostic.Diagnostic(pod_name, verbose=0)[source]¶ Bases:
objectClass holding configuration for a diagnostic script.
This is the analogue of TestCase in the xUnit analogy.
Object attributes are read from entries in the settings section of the POD’s settings.json file upon initialization.
- Attributes
driver (
str) – Filename of the top-level driver script for the POD.long_name (
str) – POD’s name used for display purposes. May contain spaces.description (
str) – Short description of POD inserted by the link in the top-level index.html file.required_programs (
listofstr, optional) – List of executables required by the POD (typically language interpreters). validate_environment.sh will make sure these are on the environment’s $PATH before the POD is run.required_ncl_scripts (
listofstr, optional) – List of NCL scripts required by the POD, if any. validate_environment.sh will make sure these are on the environment’s $PATH before the POD is run.
-
__init__(pod_name, verbose=0)[source]¶ POD initializer. Given a POD name, we attempt to read a settings.json file in a subdirectory of
/diagnosticsby that name and parse the contents.
-
iter_vars_and_alts()[source]¶ Generator iterating over all variables and alternates in POD’s varlist.
-
setUp(verbose=0)[source]¶ Perform filesystem operations and checks prior to running the POD.
In order, this 1) sets environment variables specific to the POD, 2) creates POD-specific working directories, and 3) checks for the existence of the POD’s driver script.
Note
The existence of data files is checked with
data_manager.DataManager.fetchData()and the runtime environment is validated separately as a function ofenvironment_manager.EnvironmentManager.run(). This is because each POD is run in a subprocess (due to the necessity of supporting multiple languages) so the validation must take place in that subprocess.- Raises:
PodRequirementFailureif requirements aren’t met. This is re-raised from the
_check_pod_driver()and_check_for_varlist_files()subroutines.
- Raises:
-
_set_pod_env_vars(verbose=0)[source]¶ Private method called by
setUp(). Sets all environment variables for POD.- Parameters
verbose (
int, optional) – Logging verbosity level. Default 0.
-
_setup_pod_directories(verbose=0)[source]¶ Private method called by
setUp().- Parameters
verbose (
int, optional) – Logging verbosity level. Default 0.
-
_check_pod_driver(verbose=0)[source]¶ Private method called by
setUp().- Parameters
verbose (
int, optional) – Logging verbosity level. Default 0.
- Raises:
PodRequirementFailureif driver script can’t be found.
-
_check_for_varlist_files(varlist, verbose=0)[source]¶ Verify that all data files needed by a POD exist locally.
Private method called by
fetchData().- Parameters
- Returns:
tupleof found and missing file lists. Note that this is called recursively.
-
run_commands()[source]¶ Produces the shell command(s) to run the POD. Called by
environment_manager.EnvironmentManager.run().
-
validate_commands()[source]¶ Produces the shell command(s) to validate the POD’s runtime environment (ie, check for all requested third-party module dependencies.)
Called by
environment_manager.EnvironmentManager.run(). Dependencies are passed as arguments to the shell scriptsrc/validate_environment.sh, which is invoked in the POD’s subprocess before the POD is run.
-
tearDown(verbose=0)[source]¶ Performs cleanup tasks when the POD has finished running.
In order, this 1) creates the POD’s HTML output page from its included template, replacing
CASENAMEand other template variables with their current values, and adds a link to the POD’s page from the top-level HTML report; 2) converts the POD’s output plots (in PS or EPS vector format) to a bitmap format for webpage display; 3) Copies all requested files to the output directory and deletes temporary files.- Parameters
verbose (
int, optional) – Logging verbosity level. Default 0.
-
make_pod_html()[source]¶ Perform templating on POD’s html results page(s).
A wrapper for
append_html_template(). Looks for all html files in POD_CODE_DIR, templates them, and copies them to POD_WK_DIR, respecting subdirectory structure (see doc forrecursive_copy()).
-
append_result_link(error=None)[source]¶ Update the top level index.html page with a link to this POD’s results.
This simply appends one of two html fragments to index.html: pod_result_snippet.html if the POD completed successfully, or pod_error_snippet.html if an exception was raised during the POD’s setup or execution.
- Parameters
error (default None) –
Exceptionobject (if any) that was raised during POD’s attempted execution. If this is None, assume that POD ran successfully.
-
verify_pod_links()[source]¶ Check for missing files linked to from POD’s html page.
See documentation for
LinkVerifier. This method calls LinkVerifier to check existence of all files linked to from the POD’s own top-level html page (after templating). If any files are missing, an error message listing them is written to the run’s index.html (located in src/html/pod_missing_snippet.html).
-
convert_pod_figures(src_subdir, dest_subdir)[source]¶ Convert all vector graphics in POD_WK_DIR/subdir to .png files using ghostscript.
All vector graphics files (identified by extension) in any subdirectory of POD_WK_DIR/src_subdir are converted to .png files by running ghostscript in a subprocess. Ghostscript is included in the _MDTF_base conda environment. Afterwards, any bitmap files (identified by extension) in any subdirectory of POD_WK_DIR/src_subdir are moved to POD_WK_DIR/dest_subdir, preserving and subdirectories (see doc for
recursive_copy().)- Parameters
src_subdir – Subdirectory tree of POD_WK_DIR to search for vector graphics files.
dest_subdir – Subdirectory tree of POD_WK_DIR to move converted bitmap files to.
-
cleanup_pod_files()[source]¶ Copy and remove remaining files to POD_WK_DIR.
In order, this 1) copies .pdf documentation (if any) from POD_CODE_DIR/doc, 2) copies any bitmap figures in any subdirectory of POD_OBS_DATA to POD_WK_DIR/obs (needed for legacy PODs without digested observational data), 3) removes vector graphics if requested, 4) removes netCDF scratch files in POD_WK_DIR if requested.
Settings are set at runtime, when
ConfigManageris initialized.