LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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 1322 of file argumentParser.py.

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

◆ 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 918 of file argumentParser.py.

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

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

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

1082 def showTaskHierarchy(config):
1083  """Print task hierarchy to stdout.
1084 
1085  Parameters
1086  ----------
1087  config : `lsst.pex.config.Config`
1088  Configuration to process.
1089  """
1090  print(u"Subtasks:")
1091  taskDict = getTaskDict(config=config)
1092 
1093  fieldNameList = sorted(taskDict.keys())
1094  for fieldName in fieldNameList:
1095  taskName = taskDict[fieldName]
1096  print(u"%s: %s" % (fieldName, taskName))
1097 
1098 
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.