LSST Applications  22.0.1,22.0.1+01bcf6a671,22.0.1+046ee49490,22.0.1+05c7de27da,22.0.1+0c6914dbf6,22.0.1+1220d50b50,22.0.1+12fd109e95,22.0.1+1a1dd69893,22.0.1+1c910dc348,22.0.1+1ef34551f5,22.0.1+30170c3d08,22.0.1+39153823fd,22.0.1+611137eacc,22.0.1+771eb1e3e8,22.0.1+94e66cc9ed,22.0.1+9a075d06e2,22.0.1+a5ff6e246e,22.0.1+a7db719c1a,22.0.1+ba0d97e778,22.0.1+bfe1ee9056,22.0.1+c4e1e0358a,22.0.1+cc34b8281e,22.0.1+d640e2c0fa,22.0.1+d72a2e677a,22.0.1+d9a6b571bd,22.0.1+e485e9761b,22.0.1+ebe8d3385e
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.pipe.base.configOverrides.ConfigExpressionParser Class Reference
Inheritance diagram for lsst.pipe.base.configOverrides.ConfigExpressionParser:

Public Member Functions

def __init__ (self, namespace)
 
def visit_Name (self, node)
 
def visit_List (self, node)
 
def visit_Tuple (self, node)
 
def visit_Constant (self, node)
 
def visit_Dict (self, node)
 
def visit_Set (self, node)
 
def visit_UnaryOp (self, node)
 
def generic_visit (self, node)
 

Public Attributes

 variables
 

Detailed Description

An expression parser that will be used to transform configuration
strings supplied from the command line or a pipeline into a python
object.

This is roughly equivalent to ast.literal_parser, but with the ability to
transform strings that are valid variable names into the value associated
with the name. Variables that should be considered valid are supplied to
the constructor as a dictionary that maps a string to its corresponding
value.

This class in an internal implementation detail, and should not be exposed
outside this module.

Parameters
----------
namespace : `dict` of `str` to variable
    This is a mapping of strings corresponding to variable names, to the
    object that is associated with that name

Definition at line 38 of file configOverrides.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.__init__ (   self,
  namespace 
)

Definition at line 59 of file configOverrides.py.

59  def __init__(self, namespace):
60  self.variables = namespace
61 

Member Function Documentation

◆ generic_visit()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.generic_visit (   self,
  node 
)
This method is called for all other node types. It will just raise
a value error, because this is a type of expression that we do not
support.

Definition at line 113 of file configOverrides.py.

113  def generic_visit(self, node):
114  """This method is called for all other node types. It will just raise
115  a value error, because this is a type of expression that we do not
116  support.
117  """
118  raise ValueError("Unable to parse string into literal expression")
119 
120 

◆ visit_Constant()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_Constant (   self,
  node 
)
This method is visited if the node is a constant

Definition at line 86 of file configOverrides.py.

86  def visit_Constant(self, node):
87  """This method is visited if the node is a constant
88  """
89  return node.value
90 

◆ visit_Dict()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_Dict (   self,
  node 
)
This method is visited if the node is a dict. It builds a dict out
of the component nodes.

Definition at line 91 of file configOverrides.py.

91  def visit_Dict(self, node):
92  """This method is visited if the node is a dict. It builds a dict out
93  of the component nodes.
94  """
95  return {self.visit(key): self.visit(value) for key, value in zip(node.keys, node.values)}
96 

◆ visit_List()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_List (   self,
  node 
)
This method is visited if the node is a list. Constructs a list out
of the sub nodes.

Definition at line 74 of file configOverrides.py.

74  def visit_List(self, node):
75  """This method is visited if the node is a list. Constructs a list out
76  of the sub nodes.
77  """
78  return [self.visit(elm) for elm in node.elts]
79 

◆ visit_Name()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_Name (   self,
  node 
)
This method gets called when the parser has determined a node
corresponds to a variable name.

Definition at line 62 of file configOverrides.py.

62  def visit_Name(self, node):
63  """This method gets called when the parser has determined a node
64  corresponds to a variable name.
65  """
66  # If the id (name) of the variable is in the dictionary of valid names,
67  # load and return the corresponding variable.
68  if node.id in self.variables:
69  return self.variables[node.id]
70  # If the node does not correspond to a valid variable, turn the name
71  # into a string, as the user likely intended it as such.
72  return f"{node.id}"
73 

◆ visit_Set()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_Set (   self,
  node 
)
This method is visited if the node is a set. It builds a set out
of the component nodes.

Definition at line 97 of file configOverrides.py.

97  def visit_Set(self, node):
98  """This method is visited if the node is a set. It builds a set out
99  of the component nodes.
100  """
101  return {self.visit(el) for el in node.elts}
102 

◆ visit_Tuple()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_Tuple (   self,
  node 
)
This method is visited if the node is a tuple. Constructs a list out
of the sub nodes, and then turns it into a tuple.

Definition at line 80 of file configOverrides.py.

80  def visit_Tuple(self, node):
81  """This method is visited if the node is a tuple. Constructs a list out
82  of the sub nodes, and then turns it into a tuple.
83  """
84  return tuple(self.visit_List(node))
85 

◆ visit_UnaryOp()

def lsst.pipe.base.configOverrides.ConfigExpressionParser.visit_UnaryOp (   self,
  node 
)
This method is visited if the node is a unary operator. Currently
The only operator we support is the negative (-) operator, all others
are passed to generic_visit method.

Definition at line 103 of file configOverrides.py.

103  def visit_UnaryOp(self, node):
104  """This method is visited if the node is a unary operator. Currently
105  The only operator we support is the negative (-) operator, all others
106  are passed to generic_visit method.
107  """
108  if isinstance(node.op, ast.USub):
109  value = self.visit(node.operand)
110  return -1*value
111  self.generic_visit(node)
112 

Member Data Documentation

◆ variables

lsst.pipe.base.configOverrides.ConfigExpressionParser.variables

Definition at line 60 of file configOverrides.py.


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