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
5859from lsst .utils .introspection import get_full_type_name
5960
@@ -245,27 +246,27 @@ def fromFile(cls, filename: str) -> Pipeline:
245246 return cls .from_uri (filename )
246247
247248 @classmethod
248- def from_uri (cls , uri : Union [ str , ButlerURI ] ) -> Pipeline :
249+ def from_uri (cls , uri : ResourcePathExpression ) -> Pipeline :
249250 """Load a pipeline defined in a pipeline yaml file at a location
250251 specified by a URI.
251252
252253 Parameters
253254 ----------
254- uri: `str` or `ButlerURI `
255- If a string is supplied this should be a URI path that points to a
256- pipeline defined in yaml format, either as a direct path to the yaml
257- file, or as a directory containing a "pipeline.yaml" file (the form
258- used by `write_to_uri` with ``expand=True``). This uri may also
259- supply additional labels to be used in subsetting the loaded
260- Pipeline. These labels are separated from the path by a \\ #, and
261- may be specified as a comma separated list, or a range denoted as
262- beginning..end. Beginning or end may be empty, in which case the
263- range will be a half open interval. Unlike python iteration bounds,
264- end bounds are *INCLUDED*. Note that range based selection is not
265- well defined for pipelines that are not linear in nature, and
266- correct behavior is not guaranteed, or may vary from run to run. The
267- same specifiers can be used with a ButlerURI object, by being the
268- sole contents in the fragments attribute.
255+ uri: convertible to `ResourcePath `
256+ If a string is supplied this should be a URI path that points to a
257+ pipeline defined in yaml format, either as a direct path to the
258+ yaml file, or as a directory containing a "pipeline.yaml" file (the
259+ form used by `write_to_uri` with ``expand=True``). This uri may
260+ also supply additional labels to be used in subsetting the loaded
261+ Pipeline. These labels are separated from the path by a \\ #, and
262+ may be specified as a comma separated list, or a range denoted as
263+ beginning..end. Beginning or end may be empty, in which case the
264+ range will be a half open interval. Unlike python iteration bounds,
265+ end bounds are *INCLUDED*. Note that range based selection is not
266+ well defined for pipelines that are not linear in nature, and
267+ correct behavior is not guaranteed, or may vary from run to run.
268+ The same specifiers can be used with a `ResourcePath` object, by
269+ being the sole contents in the fragments attribute.
269270
270271 Returns
271272 -------
@@ -359,7 +360,7 @@ def subsetFromLabels(self, labelSpecifier: LabelSpecifier) -> Pipeline:
359360 return Pipeline .fromIR (self ._pipelineIR .subset_from_labels (labelSet ))
360361
361362 @staticmethod
362- def _parse_file_specifier (uri : Union [ str , ButlerURI ] ) -> Tuple [ButlerURI , Optional [LabelSpecifier ]]:
363+ def _parse_file_specifier (uri : ResourcePathExpression ) -> Tuple [ResourcePath , Optional [LabelSpecifier ]]:
363364 """Split appart a uri and any possible label subsets"""
364365 if isinstance (uri , str ):
365366 # This is to support legacy pipelines during transition
@@ -373,9 +374,9 @@ def _parse_file_specifier(uri: Union[str, ButlerURI]) -> Tuple[ButlerURI, Option
373374 )
374375 if uri .count ("#" ) > 1 :
375376 raise ValueError ("Only one set of labels is allowed when specifying a pipeline to load" )
376- uri = ButlerURI (uri )
377+ uri = ResourcePath (uri )
377378 elif isinstance (uri , Path ):
378- uri = ButlerURI (uri )
379+ uri = ResourcePath (uri )
379380 label_subset = uri .fragment or None
380381
381382 specifier : Optional [LabelSpecifier ]
@@ -595,19 +596,19 @@ def toFile(self, filename: str) -> None:
595596
596597 def write_to_uri (
597598 self ,
598- uri : Union [ str , ButlerURI ] ,
599+ uri : ResourcePathExpression ,
599600 expand : bool = False ,
600601 task_defs : Optional [Iterable [TaskDef ]] = None ,
601602 ) -> None :
602603 """Write the pipeline to a file or directory.
603604
604605 Parameters
605606 ----------
606- uri : `str` or `ButlerURI `
607- URI to write to; may have any scheme with `ButlerURI ` write
608- or no scheme for a local file/directory. Should have a ``.yaml``
609- extension if ``expand=False`` and a trailing slash (indicating
610- a directory-like URI) if ``expand=True``.
607+ uri : convertible to `ResourcePath `
608+ URI to write to; may have any scheme with `ResourcePath ` write
609+ support or no scheme for a local file/directory. Should have a
610+ ``.yaml`` extension if ``expand=False`` and a trailing slash
611+ (indicating a directory-like URI) if ``expand=True``.
611612 expand : `bool`, optional
612613 If `False`, write the pipeline to a single YAML file with
613614 references to configuration files and other config overrides
@@ -627,7 +628,7 @@ def write_to_uri(
627628 raise RuntimeError (
628629 f"Expanded pipelines are written to directories, not YAML files like { uri } ."
629630 )
630- self ._write_expanded_dir (ButlerURI (uri , forceDirectory = True ), task_defs = task_defs )
631+ self ._write_expanded_dir (ResourcePath (uri , forceDirectory = True ), task_defs = task_defs )
631632 else :
632633 self ._pipelineIR .write_to_uri (uri )
633634
@@ -741,16 +742,16 @@ def description(self) -> str:
741742 """The string description of the pipeline."""
742743 return self ._pipelineIR .description
743744
744- def _write_expanded_dir (self , uri : ButlerURI , task_defs : Optional [Iterable [TaskDef ]] = None ) -> None :
745+ def _write_expanded_dir (self , uri : ResourcePath , task_defs : Optional [Iterable [TaskDef ]] = None ) -> None :
745746 """Internal implementation of `write_to_uri` with ``expand=True`` and
746747 a directory-like URI.
747748
748749 Parameters
749750 ----------
750- uri : `str` or `ButlerURI `
751- URI to write to; may have any scheme with `ButlerURI ` write or no
752- scheme for a local file/directory. Should have a trailing slash
753- (indicating a directory-like URI).
751+ uri : `ResourcePath `
752+ URI to write to; may have any scheme with `ResourcePath ` write
753+ support or no scheme for a local file/directory. Should have a
754+ trailing slash (indicating a directory-like URI).
754755 task_defs : `Iterable` [ `TaskDef` ], optional
755756 Output of `toExpandedPipeline`; may be passed to avoid a second
756757 call to that method internally.
0 commit comments