Skip to content

Commit

Permalink
WIP: reworking along TJ's lines
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulPrice committed Jul 11, 2022
1 parent c885816 commit 654c361
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions python/lsst/pipe/base/executionButlerBuilder.py
Expand Up @@ -228,8 +228,30 @@ def _export(


def _setupNewButler(
butler: Butler, outputLocation: ResourcePath, dirExists: bool, transfer: bool = False
butler: Butler,
outputLocation: ResourcePath,
dirExists: bool,
datastoreRoot: Optional[str] = None,
) -> Butler:
"""Set up the execution butler
Parameters
----------
butler : `Butler`
The original butler, upon which the execution butler is based.
outputLocation : `ResourcePath`
Location of the execution butler.
dirExists : `bool`
Does the ``outputLocation`` exist, and if so, should it be clobbered?
datastoreRoot : `str`, optional
Path for the execution butler datastore. If not specified, then the
original butler's datastore will be used.
Returns
-------
execution_butler : `Butler`
Execution butler.
"""
# Set up the new butler object at the specified location
if dirExists:
# Remove the existing table, if the code got this far and this exists
Expand All @@ -254,9 +276,10 @@ def _setupNewButler(

# record the current root of the datastore if it is specified relative
# to the butler root
butlerDir = butler._config.configDir
if config.get(("datastore", "root")) == BUTLER_ROOT_TAG and butlerDir is not None:
config["datastore", "root"] = (outputLocation if transfer else butlerDir).geturl()
if datastoreRoot is not None:
config["datastore", "root"] = datastoreRoot
elif config.get(("datastore", "root")) == BUTLER_ROOT_TAG and butler._config.configDir is not None:
config["datastore", "root"] = butler._config.configDir.geturl()
config["datastore", "trust_get_request"] = True

# Requires that we use the dimension configuration from the original
Expand Down Expand Up @@ -328,7 +351,8 @@ def buildExecutionButler(
clobber: bool = False,
butlerModifier: Optional[Callable[[Butler], Butler]] = None,
collections: Optional[Iterable[str]] = None,
transfer: str = "none",
datastore_root: Optional[str] = None,
transfer: str = "auto",
) -> Butler:
r"""buildExecutionButler is a function that is responsible for exporting
input `QuantumGraphs` into a new minimal `~lsst.daf.butler.Butler` which
Expand Down Expand Up @@ -372,11 +396,13 @@ def buildExecutionButler(
`~lsst.daf.butler.Butler` when creating the execution butler. If not
supplied the `~lsst.daf.butler.Butler`\ 's `~lsst.daf.butler.Registry`
default collections will be used.
datastore_root : `str`, Optional
Root directory for datastore of execution butler. If `None`, then the
original butler's datastore will be used.
transfer : `str`
How (and whether) the input datasets should be added to the execution
butler datastore. If `"none"`, no transfer will be made, and the
original datastore utilised. Otherwise, this should be a ``transfer``
string recognized by :func:`lsst.resources.ResourcePath.transfer_from`.
butler datastore. This should be a ``transfer`` string recognized by
:func:`lsst.resources.ResourcePath.transfer_from`.
Returns
-------
Expand Down Expand Up @@ -410,15 +436,15 @@ def buildExecutionButler(
exports, inserts = _accumulate(graph, dataset_types)
yamlBuffer = _export(butler, collections, exports, inserts)

newButler = _setupNewButler(butler, outputLocation, dirExists)
newButler = _setupNewButler(butler, outputLocation, dirExists, datastore_root)

newButler = _import(yamlBuffer, newButler, inserts, run, butlerModifier)

# Transfer the existing datasets directly from the source butler.
newButler.transfer_from(
butler,
exports,
transfer="auto" if transfer == "none" else transfer,
transfer=transfer,
skip_missing=False, # Everything should exist.
register_dataset_types=True,
)
Expand Down

0 comments on commit 654c361

Please sign in to comment.