Skip to content

Commit 125bea8

Browse files
authored
v3: Fixes for Spack, NAG, and Python 3.11 (#4671)
1 parent 888baab commit 125bea8

3 files changed

Lines changed: 48 additions & 43 deletions

File tree

Apps/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
# We could leave these in the source directory, and just broaden the search path
44
# in the other libaries, but this make it explicit which aspects are externally
55
# used.
6+
#
7+
# Note: We use configure_file(... COPYONLY) instead of file(COPY ...) here
8+
# so that CMake registers these scripts as dependencies. If you edit the source
9+
# scripts, the build system will automatically detect the change and re-copy
10+
# them to the build/install directories without needing a manual re-run of CMake.
611

7-
file (COPY MAPL_GridCompSpecs_ACG.py DESTINATION ${esma_etc}/MAPL)
8-
file (COPY MAPL_GridCompSpecs_ACGv3.py DESTINATION ${esma_etc}/MAPL)
9-
file (COPY mapl_acg.pl DESTINATION ${esma_etc}/MAPL)
10-
file (COPY mapl_stub.pl DESTINATION ${esma_etc}/MAPL)
12+
configure_file (MAPL_GridCompSpecs_ACG.py ${esma_etc}/MAPL/MAPL_GridCompSpecs_ACG.py COPYONLY)
13+
configure_file (MAPL_GridCompSpecs_ACGv3.py ${esma_etc}/MAPL/MAPL_GridCompSpecs_ACGv3.py COPYONLY)
14+
configure_file (mapl_acg.pl ${esma_etc}/MAPL/mapl_acg.pl COPYONLY)
15+
configure_file (mapl_stub.pl ${esma_etc}/MAPL/mapl_stub.pl COPYONLY)
1116

1217
install (PROGRAMS
1318
MAPL_GridCompSpecs_ACG.py

Apps/MAPL_GridCompSpecs_ACGv3.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
MANDATORY = 'mandatory'
3333

3434
# additional str constants including keys
35-
ARGS = 'args'
35+
ARGS = 'args'
3636
CONSTANTS = 'constants'
3737
CONTROL = 'control'
3838
CONTROLS = 'controls'
@@ -43,7 +43,7 @@
4343
GET = 'get'
4444
MAKE_BLOCK = 'make_block'
4545
INTENT_PREFIX = 'ESMF_STATEINTENT_'
46-
MAPPED = 'mapped'
46+
MAPPED = 'mapped'
4747
MAPPING = 'mapping'
4848
MISSING_MANDATORY = 'missing_mandatory'
4949
NONES = 'nones'
@@ -65,7 +65,7 @@
6565
CONDITION = 'condition'
6666
DIMS = 'dims'
6767
EXPORT_NAME = 'export_name'
68-
INTENT_ARG = 'intent_arg'
68+
INTENT_ARG = 'intent_arg'
6969
INTERNAL_NAME = 'internal_name'
7070
MANGLED = 'mangled'
7171
STANDARD_NAME_ARG = 'standard_name_arg'
@@ -149,51 +149,51 @@ def get_options(args):
149149
intents = [f"{INTENT_PREFIX}{state.upper()}" for state in states]
150150
options = {}
151151
# spec columns
152-
options[SPECIFICATIONS] = {
153-
DIMS: {FLAGS: {MANDATORY}, MAPPING: {
152+
options[SPECIFICATIONS] = {
153+
DIMS: {FLAGS: {MANDATORY}, MAPPING: {
154154
'z': "'z'",
155155
'xy': "'xy'",
156156
'xyz': "'xyz'",
157157
'MAPL_DimsVertOnly': "'z'",
158158
'MAPL_DimsHorzOnly': "'xy'",
159159
'MAPL_DimsHorzVert': "'xyz'"}},
160160
SHORT_NAME: {MAPPING: MANGLED, FLAGS: MANDATORY},
161-
STATE_INTENT: {FLAGS: {MANDATORY}},
162-
STANDARD_NAME: {FLAGS: MANDATORY},
163-
PRECISION: {},
164-
UNGRIDDED_DIMS: {MAPPING: ARRAY},
165-
VSTAGGER: {FLAGS: MANDATORY, MAPPING: {
161+
STATE_INTENT: {FLAGS: {MANDATORY}},
162+
STANDARD_NAME: {FLAGS: MANDATORY},
163+
PRECISION: {},
164+
UNGRIDDED_DIMS: {MAPPING: ARRAY},
165+
VSTAGGER: {FLAGS: MANDATORY, MAPPING: {
166166
'C': 'VERTICAL_STAGGER_CENTER',
167167
'E': 'VERTICAL_STAGGER_EDGE',
168168
'N': 'VERTICAL_STAGGER_NONE'}},
169-
ALIAS: {FLAGS: {STORE}},
170-
ALLOC: {FLAGS: {STORE}},
169+
ALIAS: {FLAGS: {STORE}},
170+
ALLOC: {FLAGS: {STORE}},
171171
ADD_TO_EXPORT: {MAPPING: STRLOGICAL},
172-
'attributes' : {MAPPING: STRINGVECTOR},
173-
CONDITION: {FLAGS: {STORE}},
174-
'dependencies': {MAPPING: STRINGVECTOR},
172+
'attributes' : {MAPPING: STRINGVECTOR},
173+
CONDITION: {FLAGS: {STORE}},
174+
'dependencies': {MAPPING: STRINGVECTOR},
175175
EXPORT_NAME: {MAPPING: STRING},
176-
'itemtype': {},
177-
'orientation': {},
178-
'regrid_method': {},
176+
'itemtype': {},
177+
'orientation': {},
178+
'regrid_method': {},
179179
'restart': {MAPPING: {
180180
'OPTIONAL': 'MAPL_RESTART_OPTIONAL',
181181
'SKIP': 'MAPL_RESTART_SKIP',
182182
'REQUIRED': 'MAPL_RESTART_REQUIRED',
183183
'BOOT': 'MAPL_RESTART_BOOT',
184184
'SKIP_INITIAL': 'MAPL_RESTART_SKIP_INITIAL'}},
185-
STATE: {FLAGS: {MANDATORY, STORE}},
186-
'typekind': {MAPPING: {
185+
STATE: {FLAGS: {MANDATORY, STORE}},
186+
'typekind': {MAPPING: {
187187
'R4': 'ESMF_Typekind_R4',
188188
'R8': 'ESMF_Typekind_R8',
189189
'I4': 'ESMF_Typekind_I4',
190190
'I8': 'ESMF_Typekind_I8'}},
191-
'units': {MAPPING: STRING},
191+
'units': {MAPPING: STRING},
192192
USE_FIELD_DICTIONARY: {MAPPING: (partial(convert_to_logical, none_on_false=True), convert_to_bool), FLAGS: COMPOSE},
193-
'vector_pair': {MAPPING: STRING}
193+
'vector_pair': {MAPPING: STRING}
194194
}
195195
# spec column aliases
196-
options[SPEC_ALIASES] = {
196+
options[SPEC_ALIASES] = {
197197
'ungrid': UNGRIDDED_DIMS,
198198
'ungridded': UNGRIDDED_DIMS,
199199
'cond': CONDITION,
@@ -209,17 +209,17 @@ def get_options(args):
209209
}
210210

211211
# flow control
212-
options[CONTROLS] = {MAKE_BLOCK: {MAPPING: MAKE_BLOCK, FLAGS: CONTROL, FROM: CONDITION}}
212+
options[CONTROLS] = {MAKE_BLOCK: {MAPPING: MAKE_BLOCK, FLAGS: CONTROL, FROM: CONDITION}}
213213

214214
# command line arguments
215215
options[ARGS] = args
216216

217217
# mappings from columns to new column
218-
options[MAPPED] = {
219-
STANDARD_NAME_ARG: {MAPPING: STANDARD_NAME, FROM: (STANDARD_NAME, STANDARD_NAME_PREFIX), AS: STANDARD_NAME},
218+
options[MAPPED] = {
219+
STANDARD_NAME_ARG: {MAPPING: STANDARD_NAME, FROM: (STANDARD_NAME, STANDARD_NAME_PREFIX), AS: STANDARD_NAME},
220220
INTENT_ARG: {FROM: (STATE_INTENT, STATE), MAPPING: (ID, dict(zip(states, intents))), FLAGS: AS},
221-
RANK: {MAPPING: RANK, FLAGS: {STORE, MANDATORY}, FROM: (DIMS, UNGRIDDED_DIMS)},
222-
STATE_ARG: {FROM: (STATE, STATE_INTENT), MAPPING: (ID, dict(zip(intents, states))), FLAGS: AS}
221+
RANK: {MAPPING: RANK, FLAGS: {STORE, MANDATORY}, FROM: (DIMS, UNGRIDDED_DIMS)},
222+
STATE_ARG: {FROM: (STATE, STATE_INTENT), MAPPING: (ID, dict(zip(intents, states))), FLAGS: AS}
223223
}
224224

225225
# internal constants
@@ -322,7 +322,7 @@ def get_args():
322322
"--longname-glob-prefix", "--longname_glob_prefix",
323323
action="store", nargs='?', default=None, dest=STANDARD_NAME_PREFIX,
324324
help="alternative prefix for long_name substitution")
325-
parser.add_argument(f"--{GC_VARIABLE}", dest=GC_VARIABLE, action="store",
325+
parser.add_argument(f"--{GC_VARIABLE}", dest=GC_VARIABLE, action="store",
326326
nargs='?', default=GC_VARIABLE_DEFAULT, help="ESMF_GridComp variable name")
327327
return parser.parse_args()
328328

@@ -423,7 +423,7 @@ def map_spec_values(values, options):
423423
# Get the FROM keys.
424424
(first, *tail) = get_from_keys(option)
425425
# Adjust name if applicable.
426-
name = option.get(AS, first if has_as_flag(option) else option_name)
426+
name = option.get(AS, first if has_as_flag(option) else option_name)
427427
# Apply mappings. The empty list is for future troubleshooting.
428428
values[name] = m(*get_from_values((first, *tail), values, options[ARGS]))
429429
return values, []
@@ -491,13 +491,13 @@ def flatten_specs(specs):
491491
case dict():
492492
flat_specs = reduce(concat, specs.values(), [])
493493
return flat_specs
494-
494+
495495
def flatten_options(o):
496496
"""Remove top level of o dict."""
497497
flat = {}
498498
for v in o.values():
499499
flat.update(v)
500-
return flat
500+
return flat
501501

502502
def open_file(component, filename, name, suffix=''):
503503
"""Construct filename from component, name, suffix if filename is not present. Then open output file."""
@@ -623,7 +623,7 @@ def isiterable(o, exclude_string = True):
623623
return False
624624
else:
625625
return True
626-
626+
627627
def make_block(condition, text, else_block=[]):
628628
"""Create an if-then-else block if there is a Fortran logical-valued condition. Add else block if present."""
629629
t = mkiterable(text)
@@ -634,7 +634,7 @@ def make_block(condition, text, else_block=[]):
634634
lines = [f"{INDENT}{l}" for l in t] + else_block
635635
# Add condition and end if.
636636
return [f"if ({condition}) then", *lines, f"end if"]
637-
637+
638638
def make_else_block(name=None):
639639
"""Make else block to nullify a pointer variable."""
640640
lines = []
@@ -648,9 +648,9 @@ def make_else_block(name=None):
648648
STRING: lambda value: add_quotes(value),
649649
STRINGVECTOR: lambda value: construct_string_vector(value),
650650
ARRAY: lambda value: mk_array(value),
651-
MANGLED: lambda name: f"'{rm_quotes(name).replace("*","'//trim(comp_name)//'")}'" if name else None,
651+
MANGLED: lambda name: f''' '{rm_quotes(name).replace("*", "'//trim(comp_name)//'")}' ''' if name else None,
652652
STANDARD_NAME: mangle_standard_name,
653-
RANK: compute_rank,
653+
RANK: compute_rank,
654654
MAKE_BLOCK: lambda value: partial(make_block, value),
655655
BOOL: convert_to_bool,
656656
STRLOGICAL: lambda s: convert_to_logical(convert_to_bool(s))
@@ -700,13 +700,13 @@ def inner(*args):
700700
return reduce(lambda a, c: c(a), funcs, *args)
701701
return inner
702702
# Return a mapping of multiple values with a sequence of functions. The number of args should match the number of mappings.
703-
case tuple() | list():
703+
case tuple() | list():
704704
funcs = tuple(make_mapping(sm, func_sequence=None, func_dict=None, flags=flags) for sm in m)
705705
def inner(*args):
706706
for f, arg in zip(funcs, args):
707707
if arg is None:
708708
continue
709-
return f(arg)
709+
return f(arg)
710710
return None
711711
return inner
712712

Apps/tests/acg3/acg3_unittests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def message(e, a):
8888
return general_msg(a, e)
8989
test_params = (
9090
TestParams(value, equal_test(expected), partial(message, expected)) for value, expected in
91-
((None, None), ('XX', r"'XX'"), ('*XX', f"'{INTERLUDE}XX'"))
91+
((None, None), ('XX', r" 'XX' "), ('*XX', " ''//trim(comp_name)//'XX' "))
9292
)
9393
for value, test, msg in test_params:
9494
a = mangle(value)

0 commit comments

Comments
 (0)