From 37c574133815ed1aadb8915bce60a22c0193f7bf Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 3 Jan 2025 15:58:27 -0700 Subject: [PATCH 1/2] Add entry point for loading translator code automatically --- pyproject.toml | 3 +++ python/lsst/obs/lsst/translators/__init__.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c2802f5ab..767536ab9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,9 @@ name = "lsst-obs-lsst" [project.entry-points.'butler.cli'] obs_lsst = "lsst.obs.lsst.cli:get_cli_subcommands" +[project.entry-points.astro_metadata_translators] +obs_lsst = "lsst.obs.lsst.translators:_force_load" + [tool.ruff] line-length = 110 target-version = "py311" diff --git a/python/lsst/obs/lsst/translators/__init__.py b/python/lsst/obs/lsst/translators/__init__.py index 687262631..92e6278a0 100644 --- a/python/lsst/obs/lsst/translators/__init__.py +++ b/python/lsst/obs/lsst/translators/__init__.py @@ -18,3 +18,10 @@ from .comCam import * from .comCamSim import * from .lsstCamSim import * + + +def _force_load(): + # This function exists solely to be loaded by the + # astro_metadata_translators entry point. The function + # will not be called. + pass From 991283f80659523b36e331146b0756f9ae118798 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Tue, 7 Jan 2025 11:09:43 -0700 Subject: [PATCH 2/2] Now return the translator names in entry point --- pyproject.toml | 2 +- python/lsst/obs/lsst/translators/__init__.py | 26 ++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 767536ab9..3bc44f9e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ name = "lsst-obs-lsst" obs_lsst = "lsst.obs.lsst.cli:get_cli_subcommands" [project.entry-points.astro_metadata_translators] -obs_lsst = "lsst.obs.lsst.translators:_force_load" +obs_lsst = "lsst.obs.lsst.translators:_register_translators" [tool.ruff] line-length = 110 diff --git a/python/lsst/obs/lsst/translators/__init__.py b/python/lsst/obs/lsst/translators/__init__.py index 92e6278a0..9677ad0a6 100644 --- a/python/lsst/obs/lsst/translators/__init__.py +++ b/python/lsst/obs/lsst/translators/__init__.py @@ -20,8 +20,24 @@ from .lsstCamSim import * -def _force_load(): - # This function exists solely to be loaded by the - # astro_metadata_translators entry point. The function - # will not be called. - pass +def _register_translators() -> list[str]: + """Ensure that the translators are loaded. + + When this function is imported we are guaranteed to also import the + translators which will automatically register themselves. + + Returns + ------- + translators : `list` [ `str` ] + The names of the translators provided by this package. + """ + return [ + LsstCamTranslator.name, + LatissTranslator.name, + LsstComCamTranslator.name, + LsstComCamSimTranslator.name, + LsstCamSimTranslator.name, + LsstCamImSimTranslator.name, + LsstUCDCamTranslator.name, + LsstCamPhoSimTranslator.name, + ]