-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use daf_butler subclass for SIAv2Handler with entry point
This provides a way for other butler universes to substitute their own handlers.
- Loading branch information
Showing
3 changed files
with
182 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This file is part of dax_obscore. | ||
# | ||
# 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/>. | ||
|
||
from __future__ import annotations | ||
|
||
from importlib.metadata import EntryPoint, entry_points | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .siav2 import SIAv2Handler | ||
|
||
|
||
def _get_siav2_entry_points() -> dict[str, EntryPoint]: | ||
plugins = entry_points(group="dax_obscore.siav2") | ||
return {p.name: p for p in plugins} | ||
|
||
|
||
def get_siav2_handler(namespace: str) -> type[SIAv2Handler]: | ||
"""Select the correct handler for this universe namespace. | ||
Parameters | ||
---------- | ||
namespace : `str` | ||
The butler dimension universe namespace. | ||
Returns | ||
------- | ||
handler : `type` [ `lsst.dax.obscore.siav2.SIAv2Handler` ] | ||
The class of handler suitable for this namespace. | ||
""" | ||
plugins = _get_siav2_entry_points() | ||
entry_point = plugins.get(namespace) | ||
if entry_point is None: | ||
known = ", ".join(plugins.keys()) | ||
raise RuntimeError( | ||
f"Unable to find suitable SIAv2 Handler for namespace {namespace} [do understand: {known}]" | ||
) | ||
func = entry_point.load() | ||
return func() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters