LSSTApplications  17.0+10,17.0+51,17.0+88,18.0.0+10,18.0.0+15,18.0.0+34,18.0.0+4,18.0.0+6,18.0.0-2-ge43143a+6,18.1.0-1-g0001055+2,18.1.0-1-g0896a44+10,18.1.0-1-g1349e88+9,18.1.0-1-g2505f39+7,18.1.0-1-g380d4d4+9,18.1.0-1-g5e4b7ea+2,18.1.0-1-g7e8fceb,18.1.0-1-g85f8cd4+7,18.1.0-1-g9a6769a+3,18.1.0-1-ga1a4c1a+6,18.1.0-1-gc037db8+2,18.1.0-1-gd55f500+3,18.1.0-1-ge10677a+7,18.1.0-10-g73b8679e+12,18.1.0-12-gf30922b,18.1.0-13-g451e75588,18.1.0-13-gbfe7f7f,18.1.0-2-g31c43f9+7,18.1.0-2-g9c63283+9,18.1.0-2-gdf0b915+9,18.1.0-2-gf03bb23+2,18.1.0-3-g52aa583+3,18.1.0-3-g8f4a2b1+1,18.1.0-3-g9cb968e+8,18.1.0-4-g7bbbad0,18.1.0-5-g510c42a+8,18.1.0-5-ga46117f,18.1.0-5-gaeab27e+9,18.1.0-6-gdda7f3e+11,18.1.0-8-g4084bf03+1,w.2019.34
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.pipe.base.argumentParser Namespace Reference

Classes

class  ArgumentParser
 
class  ConfigDatasetType
 
class  ConfigFileAction
 
class  ConfigValueAction
 
class  DataIdArgument
 
class  DataIdContainer
 
class  DatasetArgument
 
class  DynamicDatasetType
 
class  IdValueAction
 
class  InputOnlyArgumentParser
 
class  LogLevelAction
 
class  ReuseAction
 

Functions

def getTaskDict (config, taskDict=None, baseName="")
 
def obeyShowArgument (showOpts, config=None, exit=False)
 
def showTaskHierarchy (config)
 
def setDottedAttr (item, name, value)
 
def getDottedAttr (item, name)
 

Variables

string DEFAULT_INPUT_NAME = "PIPE_INPUT_ROOT"
 
string DEFAULT_CALIB_NAME = "PIPE_CALIB_ROOT"
 
string DEFAULT_OUTPUT_NAME = "PIPE_OUTPUT_ROOT"
 

Function Documentation

◆ getDottedAttr()

def lsst.pipe.base.argumentParser.getDottedAttr (   item,
  name 
)
Get an attribute (like `getattr` but accepts hierarchical names
such as ``foo.bar.baz``).

Parameters
----------
item : obj
    Object whose attribute is to be returned.
name : `str`
    Name of the attribute to get.

Returns
-------
itemAttr : obj
    If name is ``foo.bar.baz then the return value is
    ``item.foo.bar.baz``.

Definition at line 1325 of file argumentParser.py.

1325 def getDottedAttr(item, name):
1326  """Get an attribute (like `getattr` but accepts hierarchical names
1327  such as ``foo.bar.baz``).
1328 
1329  Parameters
1330  ----------
1331  item : obj
1332  Object whose attribute is to be returned.
1333  name : `str`
1334  Name of the attribute to get.
1335 
1336  Returns
1337  -------
1338  itemAttr : obj
1339  If name is ``foo.bar.baz then the return value is
1340  ``item.foo.bar.baz``.
1341  """
1342  subitem = item
1343  for subname in name.split("."):
1344  subitem = getattr(subitem, subname)
1345  return subitem
1346 

◆ getTaskDict()

def lsst.pipe.base.argumentParser.getTaskDict (   config,
  taskDict = None,
  baseName = "" 
)
Get a dictionary of task info for all subtasks in a config

Parameters
----------
config : `lsst.pex.config.Config`
    Configuration to process.
taskDict : `dict`, optional
    Users should not specify this argument. Supports recursion.
    If provided, taskDict is updated in place, else a new `dict`
    is started.
baseName : `str`, optional
    Users should not specify this argument. It is only used for
    recursion: if a non-empty string then a period is appended
    and the result is used as a prefix for additional entries
    in taskDict; otherwise no prefix is used.

Returns
-------
taskDict : `dict`
    Keys are config field names, values are task names.

Notes
-----
This function is designed to be called recursively.
The user should call with only a config (leaving taskDict and baseName
at their default values).

Definition at line 921 of file argumentParser.py.

921 def getTaskDict(config, taskDict=None, baseName=""):
922  """Get a dictionary of task info for all subtasks in a config
923 
924  Parameters
925  ----------
926  config : `lsst.pex.config.Config`
927  Configuration to process.
928  taskDict : `dict`, optional
929  Users should not specify this argument. Supports recursion.
930  If provided, taskDict is updated in place, else a new `dict`
931  is started.
932  baseName : `str`, optional
933  Users should not specify this argument. It is only used for
934  recursion: if a non-empty string then a period is appended
935  and the result is used as a prefix for additional entries
936  in taskDict; otherwise no prefix is used.
937 
938  Returns
939  -------
940  taskDict : `dict`
941  Keys are config field names, values are task names.
942 
943  Notes
944  -----
945  This function is designed to be called recursively.
946  The user should call with only a config (leaving taskDict and baseName
947  at their default values).
948  """
949  if taskDict is None:
950  taskDict = dict()
951  for fieldName, field in config.items():
952  if hasattr(field, "value") and hasattr(field, "target"):
953  subConfig = field.value
954  if isinstance(subConfig, pexConfig.Config):
955  subBaseName = "%s.%s" % (baseName, fieldName) if baseName else fieldName
956  try:
957  taskName = "%s.%s" % (field.target.__module__, field.target.__name__)
958  except Exception:
959  taskName = repr(field.target)
960  taskDict[subBaseName] = taskName
961  getTaskDict(config=subConfig, taskDict=taskDict, baseName=subBaseName)
962  return taskDict
963 
964 
def getTaskDict(config, taskDict=None, baseName="")

◆ obeyShowArgument()

def lsst.pipe.base.argumentParser.obeyShowArgument (   showOpts,
  config = None,
  exit = False 
)
Process arguments specified with ``--show`` (but ignores
``"data"``).

Parameters
----------
showOpts : `list` of `str`
    List of options passed to ``--show``.
config : optional
    The provided config.
exit : bool, optional
    Exit if ``"run"`` isn't included in ``showOpts``.

Parameters
----------
Supports the following options in showOpts:

- ``config[=PAT]``. Dump all the config entries, or just the ones that
    match the glob pattern.
- ``history=PAT``. Show where the config entries that match the glob
    pattern were set.
- ``tasks``. Show task hierarchy.
- ``data``. Ignored; to be processed by caller.
- ``run``. Keep going (the default behaviour is to exit if
    ``--show`` is specified).

Calls ``sys.exit(1)`` if any other option found.

Definition at line 965 of file argumentParser.py.

965 def obeyShowArgument(showOpts, config=None, exit=False):
966  """Process arguments specified with ``--show`` (but ignores
967  ``"data"``).
968 
969  Parameters
970  ----------
971  showOpts : `list` of `str`
972  List of options passed to ``--show``.
973  config : optional
974  The provided config.
975  exit : bool, optional
976  Exit if ``"run"`` isn't included in ``showOpts``.
977 
978  Parameters
979  ----------
980  Supports the following options in showOpts:
981 
982  - ``config[=PAT]``. Dump all the config entries, or just the ones that
983  match the glob pattern.
984  - ``history=PAT``. Show where the config entries that match the glob
985  pattern were set.
986  - ``tasks``. Show task hierarchy.
987  - ``data``. Ignored; to be processed by caller.
988  - ``run``. Keep going (the default behaviour is to exit if
989  ``--show`` is specified).
990 
991  Calls ``sys.exit(1)`` if any other option found.
992  """
993  if not showOpts:
994  return
995 
996  for what in showOpts:
997  showCommand, showArgs = what.split("=", 1) if "=" in what else (what, "")
998 
999  if showCommand == "config":
1000  matConfig = re.search(r"^(?:config.)?(.+)?", showArgs)
1001  pattern = matConfig.group(1)
1002  if pattern:
1003  class FilteredStream:
1004  """A file object that only prints lines
1005  that match the glob "pattern".
1006 
1007  N.b. Newlines are silently discarded and reinserted;
1008  crude but effective.
1009  """
1010 
1011  def __init__(self, pattern):
1012  # obey case if pattern isn't lowecase or requests NOIGNORECASE
1013  mat = re.search(r"(.*):NOIGNORECASE$", pattern)
1014 
1015  if mat:
1016  pattern = mat.group(1)
1017  self._pattern = re.compile(fnmatch.translate(pattern))
1018  else:
1019  if pattern != pattern.lower():
1020  print(u"Matching \"%s\" without regard to case "
1021  "(append :NOIGNORECASE to prevent this)" % (pattern,), file=sys.stdout)
1022  self._pattern = re.compile(fnmatch.translate(pattern), re.IGNORECASE)
1023 
1024  def write(self, showStr):
1025  showStr = showStr.rstrip()
1026  # Strip off doc string line(s) and cut off
1027  # at "=" for string matching
1028  matchStr = showStr.split("\n")[-1].split("=")[0]
1029  if self._pattern.search(matchStr):
1030  print(u"\n" + showStr)
1031 
1032  fd = FilteredStream(pattern)
1033  else:
1034  fd = sys.stdout
1035 
1036  config.saveToStream(fd, "config")
1037  elif showCommand == "history":
1038  matHistory = re.search(r"^(?:config.)?(.+)?", showArgs)
1039  globPattern = matHistory.group(1)
1040  if not globPattern:
1041  print("Please provide a value with --show history (e.g. history=*.doXXX)", file=sys.stderr)
1042  sys.exit(1)
1043 
1044  error = False
1045  for i, pattern in enumerate(fnmatch.filter(config.names(), globPattern)):
1046  if i > 0:
1047  print("")
1048 
1049  pattern = pattern.split(".")
1050  cpath, cname = pattern[:-1], pattern[-1]
1051  hconfig = config # the config that we're interested in
1052  for i, cpt in enumerate(cpath):
1053  try:
1054  hconfig = getattr(hconfig, cpt)
1055  except AttributeError:
1056  print("Error: configuration %s has no subconfig %s" %
1057  (".".join(["config"] + cpath[:i]), cpt), file=sys.stderr)
1058  error = True
1059 
1060  try:
1061  print(pexConfig.history.format(hconfig, cname))
1062  except KeyError:
1063  print("Error: %s has no field %s" % (".".join(["config"] + cpath), cname),
1064  file=sys.stderr)
1065  error = True
1066 
1067  if error:
1068  sys.exit(1)
1069 
1070  elif showCommand == "data":
1071  pass
1072  elif showCommand == "run":
1073  pass
1074  elif showCommand == "tasks":
1075  showTaskHierarchy(config)
1076  else:
1077  print(u"Unknown value for show: %s (choose from '%s')" %
1078  (what, "', '".join("config[=XXX] data history=XXX tasks run".split())), file=sys.stderr)
1079  sys.exit(1)
1080 
1081  if exit and "run" not in showOpts:
1082  sys.exit(0)
1083 
1084 
def obeyShowArgument(showOpts, config=None, exit=False)
def __init__(self, minimum, dataRange, Q)

◆ setDottedAttr()

def lsst.pipe.base.argumentParser.setDottedAttr (   item,
  name,
  value 
)
Set an instance attribute (like `setattr` but accepting
hierarchical names such as ``foo.bar.baz``).

Parameters
----------
item : obj
    Object whose attribute is to be set.
name : `str`
    Name of attribute to set.
value : obj
    New value for the attribute.

Notes
-----
For example if name is ``foo.bar.baz`` then ``item.foo.bar.baz``
is set to the specified value.

Definition at line 1300 of file argumentParser.py.

1300 def setDottedAttr(item, name, value):
1301  """Set an instance attribute (like `setattr` but accepting
1302  hierarchical names such as ``foo.bar.baz``).
1303 
1304  Parameters
1305  ----------
1306  item : obj
1307  Object whose attribute is to be set.
1308  name : `str`
1309  Name of attribute to set.
1310  value : obj
1311  New value for the attribute.
1312 
1313  Notes
1314  -----
1315  For example if name is ``foo.bar.baz`` then ``item.foo.bar.baz``
1316  is set to the specified value.
1317  """
1318  subitem = item
1319  subnameList = name.split(".")
1320  for subname in subnameList[:-1]:
1321  subitem = getattr(subitem, subname)
1322  setattr(subitem, subnameList[-1], value)
1323 
1324 
def setDottedAttr(item, name, value)

◆ showTaskHierarchy()

def lsst.pipe.base.argumentParser.showTaskHierarchy (   config)
Print task hierarchy to stdout.

Parameters
----------
config : `lsst.pex.config.Config`
    Configuration to process.

Definition at line 1085 of file argumentParser.py.

1085 def showTaskHierarchy(config):
1086  """Print task hierarchy to stdout.
1087 
1088  Parameters
1089  ----------
1090  config : `lsst.pex.config.Config`
1091  Configuration to process.
1092  """
1093  print(u"Subtasks:")
1094  taskDict = getTaskDict(config=config)
1095 
1096  fieldNameList = sorted(taskDict.keys())
1097  for fieldName in fieldNameList:
1098  taskName = taskDict[fieldName]
1099  print(u"%s: %s" % (fieldName, taskName))
1100 
1101 
def getTaskDict(config, taskDict=None, baseName="")

Variable Documentation

◆ DEFAULT_CALIB_NAME

string lsst.pipe.base.argumentParser.DEFAULT_CALIB_NAME = "PIPE_CALIB_ROOT"

Definition at line 45 of file argumentParser.py.

◆ DEFAULT_INPUT_NAME

string lsst.pipe.base.argumentParser.DEFAULT_INPUT_NAME = "PIPE_INPUT_ROOT"

Definition at line 44 of file argumentParser.py.

◆ DEFAULT_OUTPUT_NAME

string lsst.pipe.base.argumentParser.DEFAULT_OUTPUT_NAME = "PIPE_OUTPUT_ROOT"

Definition at line 46 of file argumentParser.py.