Coverage for python/lsst/ctrl/mpexec/util.py : 11%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of ctrl_mpexec. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# ------------------------------- # Imports of standard modules -- # -------------------------------
# ----------------------------- # Imports for other modules -- # -----------------------------
# ---------------------------------- # Local non-exported definitions -- # ----------------------------------
# ------------------------ # Exported definitions -- # ------------------------
"""!Context manager for profiling with cProfile
@param filename filename to which to write profile (profiling disabled if None or empty) @param log log object for logging the profile operations
If profiling is enabled, the context manager returns the cProfile.Profile object (otherwise it returns None), which allows additional control over profiling. You can obtain this using the "as" clause, e.g.:
with profile(filename) as prof: runYourCodeHere()
The output cumulative profile can be printed with a command-line like:
python -c 'import pstats; pstats.Stats("<filename>").sort_stats("cumtime").print_stats(30)' """ if not filename: # Nothing to do yield return from cProfile import Profile
prof = Profile() if log is not None: log.info("Enabling cProfile profiling") prof.enable() yield prof prof.disable() prof.dump_stats(filename) if log is not None: log.info("cProfile stats written to %s" % filename)
"""Nice formatting of 2-column table.
Parameters ---------- rows : `list` of `tuple` Each item in the list is a 2-tuple containg left and righ column values header: `tuple` or `None` If `None` then table header are not prined, otherwise it's a 2-tuple with column headings. """ if not rows: return width = max(len(x[0]) for x in rows) if header: width = max(width, len(header[0])) print(header[0].ljust(width), header[1]) print("".ljust(width, "-"), "".ljust(len(header[1]), "-")) for col1, col2 in rows: print(col1.ljust(width), col2)
"""Finds list of tasks matching given name.
For matching task either task label or task name after last dot should be identical to `name`. If task label is non-empty then task name is not checked.
Parameters ---------- pipeline : `Pipeline` name : str or none If empty or None then all tasks are returned
Returns ------- Lsit of `TaskDef` instances. """ if not name: return list(pipeline) tasks = [] for taskDef in pipeline: if taskDef.label: if taskDef.label == name: tasks.append(taskDef) elif taskDef.taskName.split('.')[-1] == name: tasks.append(taskDef) return tasks
"""Recursively generates subtask names.
Parameters ---------- config : `lsst.pex.config.Config` Configuration of the task
Returns ------- Iterator which returns tuples of (configFieldPath, taskName). """ for fieldName, field in sorted(config.items()): if hasattr(field, "value") and hasattr(field, "target"): subConfig = field.value if isinstance(subConfig, pexConfig.Config): try: taskName = "%s.%s" % (field.target.__module__, field.target.__name__) except Exception: taskName = repr(field.target) yield fieldName, taskName for subFieldName, taskName in subTaskIter(subConfig): yield fieldName + '.' + subFieldName, taskName |