LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
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 1329 of file argumentParser.py.

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

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

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

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

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

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

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

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

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.

lsst.pipe.base.argumentParser.showTaskHierarchy
def showTaskHierarchy(config)
Definition: argumentParser.py:1089
lsst.pipe.base.argumentParser.setDottedAttr
def setDottedAttr(item, name, value)
Definition: argumentParser.py:1304
lsst.pipe.base.argumentParser.obeyShowArgument
def obeyShowArgument(showOpts, config=None, exit=False)
Definition: argumentParser.py:968
lsst.pipe.tasks.mergeDetections.write
def write(self, patchRef, catalog)
Write the output.
Definition: mergeDetections.py:388
lsst.pipe.base.argumentParser.getTaskDict
def getTaskDict(config, taskDict=None, baseName="")
Definition: argumentParser.py:924
lsst.pipe.base.argumentParser.getDottedAttr
def getDottedAttr(item, name)
Definition: argumentParser.py:1329