Reference Guide  2.5.0
psyclone.domain.lfric.kernel.common_metadata.CommonMetadata Class Reference
Inheritance diagram for psyclone.domain.lfric.kernel.common_metadata.CommonMetadata:
Collaboration diagram for psyclone.domain.lfric.kernel.common_metadata.CommonMetadata:

Public Member Functions

def create_from_fortran_string (cls, fortran_string)
 

Static Public Member Functions

def check_fparser2 (fparser2_tree, encoding)
 
def validate_scalar_value (value, valid_values, name)
 
def create_fparser2 (fortran_string, encoding)
 
def create_from_fparser2 (fparser2_tree)
 

Static Public Attributes

 fparser2_class = None
 

Detailed Description

Abstract class to capture common LFRic kernel metadata.

Definition at line 49 of file common_metadata.py.

Member Function Documentation

◆ check_fparser2()

def psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.check_fparser2 (   fparser2_tree,
  encoding 
)
static
Checks that the fparser2 tree is valid.

:param fparser2_tree: fparser2 tree capturing a metadata argument.
:type fparser2_tree: :py:class:`fparser.two.Fortran2003.Base`
:param encoding: class in which the fparser2 tree should \
    be encoded.
:type encoding: :py:class:`fparser.two.Fortran2003.Base`

:raises TypeError: if the fparser2_tree argument is not of the \
    type specified by the encoding argument.

Definition at line 56 of file common_metadata.py.

56  def check_fparser2(fparser2_tree, encoding):
57  '''Checks that the fparser2 tree is valid.
58 
59  :param fparser2_tree: fparser2 tree capturing a metadata argument.
60  :type fparser2_tree: :py:class:`fparser.two.Fortran2003.Base`
61  :param encoding: class in which the fparser2 tree should \
62  be encoded.
63  :type encoding: :py:class:`fparser.two.Fortran2003.Base`
64 
65  :raises TypeError: if the fparser2_tree argument is not of the \
66  type specified by the encoding argument.
67 
68  '''
69  if not isinstance(fparser2_tree, encoding):
70  raise TypeError(
71  f"Expected kernel metadata to be encoded as an "
72  f"fparser2 {encoding.__name__} object but found type "
73  f"'{type(fparser2_tree).__name__}' with value "
74  f"'{str(fparser2_tree)}'.")
75 

◆ create_fparser2()

def psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.create_fparser2 (   fortran_string,
  encoding 
)
static
Creates an fparser2 tree from a Fortran string. The resultant
parent node of the tree will be the same type as the encoding
argument if the string conforms to the encoding, otherwise an
exception will be raised.

TODO: issue #1965: relocate this method as it is not specific
to metadata processing.

:param str fortran_string: a string containing the metadata in \
   Fortran.
:param encoding: the parent class with which we will encode the \
    Fortran string.
:type encoding: subclass of :py:class:`fparser.two.Fortran2003.Base`

:returns: an fparser2 tree containing a metadata \
    argument.
:rtype: subclass of :py:class:`fparser.two.Fortran2003.Base`

:raises ValueError: if the Fortran string is not in the \
    expected form.

Definition at line 100 of file common_metadata.py.

100  def create_fparser2(fortran_string, encoding):
101  '''Creates an fparser2 tree from a Fortran string. The resultant
102  parent node of the tree will be the same type as the encoding
103  argument if the string conforms to the encoding, otherwise an
104  exception will be raised.
105 
106  TODO: issue #1965: relocate this method as it is not specific
107  to metadata processing.
108 
109  :param str fortran_string: a string containing the metadata in \
110  Fortran.
111  :param encoding: the parent class with which we will encode the \
112  Fortran string.
113  :type encoding: subclass of :py:class:`fparser.two.Fortran2003.Base`
114 
115  :returns: an fparser2 tree containing a metadata \
116  argument.
117  :rtype: subclass of :py:class:`fparser.two.Fortran2003.Base`
118 
119  :raises ValueError: if the Fortran string is not in the \
120  expected form.
121 
122  '''
123  _ = ParserFactory().create(std="f2003")
124  reader = FortranStringReader(fortran_string)
125  match = True
126  try:
127  fparser2_tree = encoding(reader)
128  except (NoMatchError, FortranSyntaxError):
129  match = False
130  if not match or not fparser2_tree:
131  raise ValueError(
132  f"Expected kernel metadata to be a Fortran "
133  f"{encoding.__name__}, but found '{fortran_string}'.")
134  return fparser2_tree
135 
Here is the caller graph for this function:

◆ create_from_fortran_string()

def psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.create_from_fortran_string (   cls,
  fortran_string 
)
Create an instance of this class from Fortran.

:param str fortran_string: a string containing the metadata in \
    Fortran.

:returns: an instance of this class.
:rtype: subclass of \
    :py:class:`python.domain.lfric.kernel.CommonMetadata`

Definition at line 137 of file common_metadata.py.

137  def create_from_fortran_string(cls, fortran_string):
138  '''Create an instance of this class from Fortran.
139 
140  :param str fortran_string: a string containing the metadata in \
141  Fortran.
142 
143  :returns: an instance of this class.
144  :rtype: subclass of \
145  :py:class:`python.domain.lfric.kernel.CommonMetadata`
146 
147  '''
148  fparser2_tree = cls.create_fparser2(fortran_string, cls.fparser2_class)
149  return cls.create_from_fparser2(fparser2_tree)
150 

References psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.create_fparser2(), psyclone.domain.lfric.kernel.common_meta_arg_metadata.CommonMetaArgMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.evaluator_targets_metadata.EvaluatorTargetsMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_args_metadata.MetaArgsMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_funcs_arg_metadata.MetaFuncsArgMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_funcs_metadata.MetaFuncsMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_mesh_arg_metadata.MetaMeshArgMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_mesh_metadata.MetaMeshMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_ref_element_arg_metadata.MetaRefElementArgMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.meta_ref_element_metadata.MetaRefElementMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.operates_on_metadata.OperatesOnMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.shapes_metadata.ShapesMetadata.create_from_fparser2(), psyclone.domain.lfric.kernel.common_arg_metadata.CommonArgMetadata.fparser2_class, psyclone.domain.lfric.kernel.common_declaration_metadata.CommonDeclarationMetadata.fparser2_class, psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.fparser2_class, psyclone.domain.lfric.kernel.inter_grid_arg_metadata.InterGridArgMetadata.fparser2_class, and psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.fparser2_class.

Here is the call graph for this function:

◆ create_from_fparser2()

◆ validate_scalar_value()

def psyclone.domain.lfric.kernel.common_metadata.CommonMetadata.validate_scalar_value (   value,
  valid_values,
  name 
)
static
Check that the value argument is one of the values supplied in the
valid_values list.

:param str value: the value being checked.
:param List[str] valid_values: a list of valid values.
:param str name: the name of the metadata being checked

:raises TypeError: if the value is not a string.
:raises ValueError: if the supplied value is not one of the \
    values in the valid_values list.

Definition at line 77 of file common_metadata.py.

77  def validate_scalar_value(value, valid_values, name):
78  '''Check that the value argument is one of the values supplied in the
79  valid_values list.
80 
81  :param str value: the value being checked.
82  :param List[str] valid_values: a list of valid values.
83  :param str name: the name of the metadata being checked
84 
85  :raises TypeError: if the value is not a string.
86  :raises ValueError: if the supplied value is not one of the \
87  values in the valid_values list.
88 
89  '''
90  if not isinstance(value, str):
91  raise TypeError(f"The '{name}' value should be of type str, but "
92  f"found '{type(value).__name__}'.")
93  if value.lower() not in valid_values:
94  raise ValueError(
95  f"The '{name}' metadata should be a recognised "
96  f"value (one of {valid_values}) "
97  f"but found '{value}'.")
98 
Here is the caller graph for this function:

The documentation for this class was generated from the following file: