5353
5454# -----------------------------
5555# Imports for other modules --
56- from lsst .daf .butler import ButlerURI , DatasetType , NamedValueSet , Registry , SkyPixDimension
56+ from lsst .daf .butler import DatasetType , NamedValueSet , Registry , SkyPixDimension
57+ from lsst .resources import ResourcePath , ResourcePathExpression
5758from lsst .utils import doImport
5859
5960from . import pipelineIR , pipeTools
@@ -246,25 +247,27 @@ def fromFile(cls, filename: str) -> Pipeline:
246247 return cls .from_uri (filename )
247248
248249 @classmethod
249- def from_uri (cls , uri : Union [ str , ButlerURI ] ) -> Pipeline :
250+ def from_uri (cls , uri : ResourcePathExpression ) -> Pipeline :
250251 """Load a pipeline defined in a pipeline yaml file at a location
251252 specified by a URI.
252253
253254 Parameters
254255 ----------
255- uri: `str` or `ButlerURI`
256- If a string is supplied this should be a URI path that points to a
257- pipeline defined in yaml format. This uri may also supply
258- additional labels to be used in subsetting the loaded Pipeline.
259- These labels are separated from the path by a \\ #, and may be
260- specified as a comma separated list, or a range denoted as
261- beginning..end. Beginning or end may be empty, in which case the
262- range will be a half open interval. Unlike python iteration
263- bounds, end bounds are *INCLUDED*. Note that range based selection
264- is not well defined for pipelines that are not linear in nature,
265- and correct behavior is not guaranteed, or may vary from run to
266- run. The same specifiers can be used with a ButlerURI object, by
267- being the sole contents in the fragments attribute.
256+ uri: convertible to `ResourcePath`
257+ If a string is supplied this should be a URI path that points to a
258+ pipeline defined in yaml format, either as a direct path to the
259+ yaml file, or as a directory containing a "pipeline.yaml" file (the
260+ form used by `write_to_uri` with ``expand=True``). This uri may
261+ also supply additional labels to be used in subsetting the loaded
262+ Pipeline. These labels are separated from the path by a \\ #, and
263+ may be specified as a comma separated list, or a range denoted as
264+ beginning..end. Beginning or end may be empty, in which case the
265+ range will be a half open interval. Unlike python iteration bounds,
266+ end bounds are *INCLUDED*. Note that range based selection is not
267+ well defined for pipelines that are not linear in nature, and
268+ correct behavior is not guaranteed, or may vary from run to run.
269+ The same specifiers can be used with a `ResourcePath` object, by
270+ being the sole contents in the fragments attribute.
268271
269272 Returns
270273 -------
@@ -356,7 +359,7 @@ def subsetFromLabels(self, labelSpecifier: LabelSpecifier) -> Pipeline:
356359 return Pipeline .fromIR (self ._pipelineIR .subset_from_labels (labelSet ))
357360
358361 @staticmethod
359- def _parse_file_specifier (uri : Union [ str , ButlerURI ] ) -> Tuple [ButlerURI , Optional [LabelSpecifier ]]:
362+ def _parse_file_specifier (uri : ResourcePathExpression ) -> Tuple [ResourcePath , Optional [LabelSpecifier ]]:
360363 """Split appart a uri and any possible label subsets"""
361364 if isinstance (uri , str ):
362365 # This is to support legacy pipelines during transition
@@ -370,7 +373,8 @@ def _parse_file_specifier(uri: Union[str, ButlerURI]) -> Tuple[ButlerURI, Option
370373 )
371374 if uri .count ("#" ) > 1 :
372375 raise ValueError ("Only one set of labels is allowed when specifying a pipeline to load" )
373- uri = ButlerURI (uri )
376+ # Everything else can be converted directly to ResourcePath.
377+ uri = ResourcePath (uri )
374378 label_subset = uri .fragment or None
375379
376380 specifier : Optional [LabelSpecifier ]
@@ -593,10 +597,16 @@ def _addConfigImpl(self, label: str, newConfig: pipelineIR.ConfigIR) -> None:
593597 def toFile (self , filename : str ) -> None :
594598 self ._pipelineIR .to_file (filename )
595599
596- def write_to_uri (self , uri : Union [str , ButlerURI ]) -> None :
597- # tasks need sorted each call because someone might have added or
598- # removed task, and caching changes does not seem worth the small
599- # overhead
600+ def write_to_uri (self , uri : ResourcePathExpression ) -> None :
601+ """Write the pipeline to a file or directory.
602+
603+ Parameters
604+ ----------
605+ uri : convertible to `ResourcePath`
606+ URI to write to; may have any scheme with `ResourcePath` write
607+ support or no scheme for a local file/directory. Should have a
608+ ``.yaml``.
609+ """
600610 labels = [td .label for td in self ._toExpandedPipelineImpl (checkContracts = False )]
601611 self ._pipelineIR .reorder_tasks (labels )
602612 self ._pipelineIR .write_to_uri (uri )
0 commit comments