Skip to content

Commit

Permalink
Merge branch 'add_const_interface' into pytest_additions
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaxmonsky committed Aug 24, 2023
2 parents b8fae25 + 3207b59 commit 475fb9b
Show file tree
Hide file tree
Showing 11 changed files with 442 additions and 392 deletions.
4 changes: 0 additions & 4 deletions scripts/ccpp_datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
from parse_tools import read_xml_file, PrettyElementTree
from suite_objects import VerticalLoop, Subcycle

# Find python version
PY3 = sys.version_info[0] > 2
PYSUBVER = sys.version_info[1]

# Global data
_INDENT_STR = " "

Expand Down
694 changes: 402 additions & 292 deletions scripts/ccpp_suite.py

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,7 @@ def escape_tex(text):

def isstring(s):
"""Return true if a variable is a string"""
# We use Python 3
if (sys.version_info.major == 3):
return isinstance(s, str)
# We use Python 2
elif (sys.version_info.major == 2):
return isinstance(s, basestring)
else:
raise Exception('Unknown Python version')
return isinstance(s, str)

def string_to_python_identifier(string):
"""Replaces forbidden characters in strings with standard substitutions
Expand Down
2 changes: 1 addition & 1 deletion scripts/constituents.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def find_variable(self, standard_name=None, source_var=None,
# end for
newdims.append(':'.join(new_dnames))
# end for
var = source_var.clone({'dimensions' : newdims}, remove_intent=False,
var = source_var.clone({'dimensions' : newdims}, remove_intent=True,
source_type=self.__constituent_type)
self.add_variable(var, self.__run_env)
return var
Expand Down
13 changes: 1 addition & 12 deletions scripts/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
import os
# CCPP framework imports
from parse_tools import CCPPError, ParseInternalError
#XXgoldyXX: v Crap required to support python 2
import sys
# Find python version
PY3 = sys.version_info[0] > 2
#XXgoldyXX: ^ Crap required to support python 2

# Standardize name of generated kinds file and module
KINDS_MODULE = 'ccpp_kinds'
Expand Down Expand Up @@ -300,13 +295,7 @@ def move_modified_files(src_dir, dest_dir, overwrite=False, remove_src=False):
fmove = True
# end if
if fmove:
#XXgoldyXX: v Crap required to support python 2
if PY3:
os.replace(src_path, dest_path)
else:
os.rename(src_path, dest_path)
# end if
#XXgoldyXX: ^ Crap required to support python 2
os.replace(src_path, dest_path)
else:
os.remove(src_path)
# end if
Expand Down
15 changes: 10 additions & 5 deletions scripts/metavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,15 +1004,15 @@ def write_def(self, outfile, indent, wdict, allocatable=False,
intent = None
# end if
if protected and allocatable:
errmsg = 'Cannot create allocatable variable from protected, {}'
errmsg = "Cannot create allocatable variable from protected, {}"
raise CCPPError(errmsg.format(name))
# end if
if dummy and (intent is None):
if add_intent is not None:
intent = add_intent
else:
errmsg = "<add_intent> is missing for dummy argument, {}"
raise CCPPError(errmsg.format(name))
errmsg = f"<add_intent> is missing for dummy argument, {name}"
raise CCPPError(errmsg)
# end if
# end if
if protected and dummy:
Expand All @@ -1025,7 +1025,12 @@ def write_def(self, outfile, indent, wdict, allocatable=False,
# end if
elif intent is not None:
alloval = self.get_prop_value('allocatable')
if (intent.lower()[-3:] == 'out') and alloval:
if alloval:
if intent.lower() == 'in':
# We should not have allocatable, intent(in), makes no sense
errmsg = f"{name} ({stdname}) is allocatable and intent(in)"
raise CCPPError(errmsg)
# end if
intent_str = f"allocatable, intent({intent})"
else:
intent_str = f"intent({intent}){' '*(5 - len(intent))}"
Expand Down Expand Up @@ -1064,7 +1069,7 @@ def write_def(self, outfile, indent, wdict, allocatable=False,
cspc = comma + ' '*(extra_space + 19 - len(vtype))
# end if
# end if

outfile.write(dstr.format(type=vtype, kind=kind, intent=intent_str,
name=name, dims=dimstr, cspc=cspc,
sname=stdname), indent)
Expand Down
12 changes: 2 additions & 10 deletions scripts/parse_tools/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

"""Classes to aid the parsing process"""

import sys
# Find python version
PY3 = sys.version_info[0] > 2

# pylint: disable=wrong-import-position
# Python library imports
if PY3:
from collections.abc import Iterable
else:
from collections import Iterable
# end if
from collections.abc import Iterable
import copy
import sys
import os.path
import logging
# CCPP framework imports
# pylint: enable=wrong-import-position

class _StdNameCounter:
"""Class to hold a global counter to avoid using global keyword"""
Expand Down
70 changes: 16 additions & 54 deletions scripts/parse_tools/xml_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
simple_tag_re = re.compile(r"([<][^/][^<>/]+[/][>])")

# Find python version
PY3 = sys.version_info[0] > 2
PYSUBVER = sys.version_info[1]
_LOGGER = None

Expand Down Expand Up @@ -56,35 +55,12 @@ def call_command(commands, logger, silent=False):
result = False
outstr = ''
try:
if PY3:
if PYSUBVER > 6:
cproc = subprocess.run(commands, check=True,
capture_output=True)
if not silent:
logger.debug(cproc.stdout)
# end if
result = cproc.returncode == 0
elif PYSUBVER >= 5:
cproc = subprocess.run(commands, check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if not silent:
logger.debug(cproc.stdout)
# end if
result = cproc.returncode == 0
else:
raise ValueError("Python 3 must be at least version 3.5")
# end if
else:
pproc = subprocess.Popen(commands, stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, _ = pproc.communicate()
if not silent:
logger.debug(output)
# end if
result = pproc.returncode == 0
cproc = subprocess.run(commands, check=True,
capture_output=True)
if not silent:
logger.debug(cproc.stdout)
# end if
result = cproc.returncode == 0
except (OSError, CCPPError, subprocess.CalledProcessError) as err:
if silent:
result = False
Expand Down Expand Up @@ -228,11 +204,7 @@ def read_xml_file(filename, logger=None):
###############################################################################
"""Read the XML file, <filename>, and return its tree and root"""
if os.path.isfile(filename) and os.access(filename, os.R_OK):
if PY3:
file_open = (lambda x: open(x, 'r', encoding='utf-8'))
else:
file_open = (lambda x: open(x, 'r'))
# end if
file_open = (lambda x: open(x, 'r', encoding='utf-8'))
with file_open(filename) as file_:
try:
tree = ET.parse(file_)
Expand Down Expand Up @@ -284,29 +256,19 @@ def write(self, file, encoding="us-ascii", xml_declaration=None,
default_namespace=None, method="xml",
short_empty_elements=True):
"""Subclassed write method to format output."""
if PY3 and (PYSUBVER >= 4):
if PYSUBVER >= 8:
et_str = ET.tostring(self.getroot(),
encoding=encoding, method=method,
xml_declaration=xml_declaration,
default_namespace=default_namespace,
short_empty_elements=short_empty_elements)
else:
et_str = ET.tostring(self.getroot(),
encoding=encoding, method=method,
short_empty_elements=short_empty_elements)
# end if
else:
if PYSUBVER >= 8:
et_str = ET.tostring(self.getroot(),
encoding=encoding, method=method)
# end if
if PY3:
fmode = 'wt'
root = str(et_str, encoding="utf-8")
encoding=encoding, method=method,
xml_declaration=xml_declaration,
default_namespace=default_namespace,
short_empty_elements=short_empty_elements)
else:
fmode = 'w'
root = et_str
et_str = ET.tostring(self.getroot(),
encoding=encoding, method=method,
short_empty_elements=short_empty_elements)
# end if
fmode = 'wt'
root = str(et_str, encoding="utf-8")
indent = 0
last_write_text = False
with open(file, fmode) as outfile:
Expand Down
9 changes: 6 additions & 3 deletions test/advection_test/test_host.F90
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,17 @@ program test
implicit none

character(len=cs), target :: test_parts1(1)
character(len=cm), target :: test_invars1(6)
character(len=cm), target :: test_outvars1(5)
character(len=cm), target :: test_reqvars1(8)
character(len=cm), target :: test_invars1(7)
character(len=cm), target :: test_outvars1(6)
character(len=cm), target :: test_reqvars1(9)

type(suite_info) :: test_suites(1)
logical :: run_okay

test_parts1 = (/ 'physics '/)
test_invars1 = (/ &
'cloud_ice_dry_mixing_ratio ', &
'cloud_liquid_dry_mixing_ratio ', &
'surface_air_pressure ', &
'temperature ', &
'time_step_for_physics ', &
Expand All @@ -510,11 +511,13 @@ program test
'ccpp_error_code ', &
'temperature ', &
'water_vapor_specific_humidity ', &
'cloud_liquid_dry_mixing_ratio ', &
'cloud_ice_dry_mixing_ratio ' /)
test_reqvars1 = (/ &
'surface_air_pressure ', &
'temperature ', &
'time_step_for_physics ', &
'cloud_liquid_dry_mixing_ratio ', &
'cloud_ice_dry_mixing_ratio ', &
'water_temperature_at_freezing ', &
'water_vapor_specific_humidity ', &
Expand Down
4 changes: 2 additions & 2 deletions test/advection_test/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
# end if

if ((sys.version_info[0] < 3) or
(sys.version_info[0] == 3) and (sys.version_info[1] < 6)):
raise Exception("Python 3.6 or greater required")
(sys.version_info[0] == 3) and (sys.version_info[1] < 7)):
raise Exception("Python 3.7 or greater required")
# end if

sys.path.append(_SCRIPTS_DIR)
Expand Down
2 changes: 1 addition & 1 deletion test/var_action_test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scriptdir="$( cd $( dirname $0 ); pwd -P )"
##
## Option default values
##
defdir="ct_build"
defdir="va_build"
build_dir="${currdir}/${defdir}"
cleanup="PASS" # Other supported options are ALWAYS and NEVER
verbosity=0
Expand Down

0 comments on commit 475fb9b

Please sign in to comment.