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
Classes | Functions | Variables
lsst.pipe.base.argumentParser Namespace Reference

Classes

class  DataIdContainer
 
class  DataIdArgument
 
class  DynamicDatasetType
 
class  DatasetArgument
 
class  ConfigDatasetType
 
class  ArgumentParser
 
class  InputOnlyArgumentParser
 
class  ConfigValueAction
 
class  ConfigFileAction
 
class  IdValueAction
 
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 1330 of file argumentParser.py.

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

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

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

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

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

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

1090 def showTaskHierarchy(config):
1091  """Print task hierarchy to stdout.
1092 
1093  Parameters
1094  ----------
1095  config : `lsst.pex.config.Config`
1096  Configuration to process.
1097  """
1098  print("Subtasks:")
1099  taskDict = getTaskDict(config=config)
1100 
1101  fieldNameList = sorted(taskDict.keys())
1102  for fieldName in fieldNameList:
1103  taskName = taskDict[fieldName]
1104  print(f"{fieldName}: {taskName}")
1105 
1106 

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.