|
3 | 3 | import logging
|
4 | 4 | import os
|
5 | 5 | import re
|
6 |
| -from collections import OrderedDict |
7 | 6 | from copy import deepcopy
|
8 | 7 | from pprint import pformat
|
9 | 8 |
|
|
35 | 34 | TASKSEP = os.sep
|
36 | 35 |
|
37 | 36 |
|
38 |
| -def ordered_safe_load(stream): |
39 |
| - """Load a YAML file using OrderedDict instead of dict.""" |
40 |
| - class OrderedSafeLoader(yaml.SafeLoader): |
41 |
| - """Loader class that uses OrderedDict to load a map.""" |
42 |
| - def construct_mapping(loader, node): |
43 |
| - """Load a map as an OrderedDict.""" |
44 |
| - loader.flatten_mapping(node) |
45 |
| - return OrderedDict(loader.construct_pairs(node)) |
46 |
| - |
47 |
| - OrderedSafeLoader.add_constructor( |
48 |
| - yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, construct_mapping) |
49 |
| - |
50 |
| - return yaml.load(stream, OrderedSafeLoader) |
51 |
| - |
52 |
| - |
53 |
| -def load_raw_recipe(filename): |
54 |
| - """Check a recipe file and return it in raw form.""" |
55 |
| - # Note that many checks can only be performed after the automatically |
56 |
| - # computed entries have been filled in by creating a Recipe object. |
| 37 | +def read_recipe_file(filename, config_user, initialize_tasks=True): |
| 38 | + """Read a recipe from file.""" |
57 | 39 | check.recipe_with_schema(filename)
|
58 | 40 | with open(filename, 'r') as file:
|
59 |
| - contents = file.read() |
60 |
| - raw_recipe = yaml.safe_load(contents) |
61 |
| - raw_recipe['preprocessors'] = ordered_safe_load(contents).get( |
62 |
| - 'preprocessors', {}) |
63 |
| - |
64 |
| - check.diagnostics(raw_recipe['diagnostics']) |
65 |
| - return raw_recipe |
66 |
| - |
| 41 | + raw_recipe = yaml.safe_load(file) |
67 | 42 |
|
68 |
| -def read_recipe_file(filename, config_user, initialize_tasks=True): |
69 |
| - """Read a recipe from file.""" |
70 |
| - raw_recipe = load_raw_recipe(filename) |
71 | 43 | return Recipe(raw_recipe,
|
72 | 44 | config_user,
|
73 | 45 | initialize_tasks,
|
74 | 46 | recipe_file=filename)
|
75 | 47 |
|
76 | 48 |
|
77 |
| -def _get_value(key, datasets): |
78 |
| - """Get a value for key by looking at the other datasets.""" |
79 |
| - values = {dataset[key] for dataset in datasets if key in dataset} |
80 |
| - |
81 |
| - if len(values) > 1: |
82 |
| - raise RecipeError("Ambiguous values {} for property {}".format( |
83 |
| - values, key)) |
84 |
| - |
85 |
| - value = None |
86 |
| - if len(values) == 1: |
87 |
| - value = values.pop() |
88 |
| - |
89 |
| - return value |
90 |
| - |
91 |
| - |
92 | 49 | def _add_cmor_info(variable, override=False):
|
93 | 50 | """Add information from CMOR tables to variable."""
|
94 | 51 | logger.debug("If not present: adding keys from CMOR table to %s", variable)
|
@@ -976,6 +933,7 @@ def _initialize_provenance(self, raw_documentation):
|
976 | 933 | def _initialize_diagnostics(self, raw_diagnostics, raw_datasets):
|
977 | 934 | """Define diagnostics in recipe."""
|
978 | 935 | logger.debug("Retrieving diagnostics from recipe")
|
| 936 | + check.diagnostics(raw_diagnostics) |
979 | 937 |
|
980 | 938 | diagnostics = {}
|
981 | 939 |
|
|
0 commit comments