diff --git a/doc/changes/DM-33226.misc.rst b/doc/changes/DM-33226.misc.rst new file mode 100644 index 000000000..a81334c22 --- /dev/null +++ b/doc/changes/DM-33226.misc.rst @@ -0,0 +1 @@ +The ``Instrument.configPaths`` property can now refer to ``lsst.resources.ResourcePath`` URIs as well as strings (paths or URI strings). diff --git a/python/lsst/pipe/base/_instrument.py b/python/lsst/pipe/base/_instrument.py index 16c74a531..bd2f19f5c 100644 --- a/python/lsst/pipe/base/_instrument.py +++ b/python/lsst/pipe/base/_instrument.py @@ -31,7 +31,6 @@ import contextlib import datetime -import os.path from abc import ABCMeta, abstractmethod from collections.abc import Sequence from typing import TYPE_CHECKING, Any, Self, cast, final @@ -39,6 +38,7 @@ from lsst.daf.butler import DataCoordinate, DataId, DimensionPacker, DimensionRecord, Formatter from lsst.daf.butler.registry import DataIdError from lsst.pex.config import Config, RegistryField +from lsst.resources import ResourcePath, ResourcePathExpression from lsst.utils import doImportType from lsst.utils.introspection import get_full_type_name @@ -65,7 +65,7 @@ class Instrument(metaclass=ABCMeta): the base class. """ - configPaths: Sequence[str] = () + configPaths: Sequence[ResourcePathExpression] = () """Paths to config files to read for specific Tasks. The paths in this list should contain files of the form `task.py`, for @@ -366,9 +366,10 @@ def applyConfigOverrides(self, name: str, config: Config) -> None: Config instance to which overrides should be applied. """ for root in self.configPaths: - path = os.path.join(root, f"{name}.py") - if os.path.exists(path): - config.load(path) + resource = ResourcePath(root, forceDirectory=True, forceAbsolute=True) + uri = resource.join(f"{name}.py", forceDirectory=False) + if uri.exists(): + config.load(uri) @staticmethod def formatCollectionTimestamp(timestamp: str | datetime.datetime) -> str: