From 641a18e69f31163c2b835c0e7dd7d49114f14494 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Fri, 30 Jun 2023 15:05:43 -0400 Subject: [PATCH] Add support for deprecating connection templates. This intentionally just deprecates the corresponding config entry, keeping those config fields from being written. The expectation is that deprecated templates may be used in also-deprecated connections without emitting another warning, and then both can be removed together. --- python/lsst/pipe/base/config.py | 5 ++++- python/lsst/pipe/base/connections.py | 9 ++++++++- tests/test_connections.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/python/lsst/pipe/base/config.py b/python/lsst/pipe/base/config.py index 21afc3ba..6e16a17c 100644 --- a/python/lsst/pipe/base/config.py +++ b/python/lsst/pipe/base/config.py @@ -146,7 +146,10 @@ def __new__( docString = "Template parameter used to format corresponding field template parameter" for templateName, default in connectionsClass.defaultTemplates.items(): configConnectionsNamespace[templateName] = TemplateField( - dtype=str, doc=docString, default=default + dtype=str, + doc=docString, + default=default, + deprecated=connectionsClass.deprecatedTemplates.get(templateName), ) # add a reference to the connection class used to create this sub # config diff --git a/python/lsst/pipe/base/connections.py b/python/lsst/pipe/base/connections.py index d2b45fe2..973aec52 100644 --- a/python/lsst/pipe/base/connections.py +++ b/python/lsst/pipe/base/connections.py @@ -225,14 +225,20 @@ def __new__(cls, name, bases, dct, **kwargs): # look up any template from base classes and merge them all # together mergeDict = {} + mergeDeprecationsDict = {} for base in bases[::-1]: if hasattr(base, "defaultTemplates"): mergeDict.update(base.defaultTemplates) + if hasattr(base, "deprecatedTemplates"): + mergeDeprecationsDict.update(base.deprecatedTemplates) if "defaultTemplates" in kwargs: mergeDict.update(kwargs["defaultTemplates"]) - + if "deprecatedTemplates" in kwargs: + mergeDeprecationsDict.update(kwargs["deprecatedTemplates"]) if len(mergeDict) > 0: kwargs["defaultTemplates"] = mergeDict + if len(mergeDeprecationsDict) > 0: + kwargs["deprecatedTemplates"] = mergeDeprecationsDict # Verify that if templated strings were used, defaults were # supplied as an argument in the declaration of the connection @@ -259,6 +265,7 @@ def __new__(cls, name, bases, dct, **kwargs): f" (conflicts are {nameTemplateIntersection})." ) dct["defaultTemplates"] = kwargs.get("defaultTemplates", {}) + dct["deprecatedTemplates"] = kwargs.get("deprecatedTemplates", {}) # Convert all the connection containers into frozensets so they cannot # be modified at the class scope diff --git a/tests/test_connections.py b/tests/test_connections.py index 29b51025..dc43020f 100644 --- a/tests/test_connections.py +++ b/tests/test_connections.py @@ -188,10 +188,15 @@ class TestConnectionsWithBrokenDimensionsIter(pipeBase.PipelineTask, dimensions= def test_deprecation(self) -> None: """Test support for deprecating connections.""" - class TestConnections(pipeBase.PipelineTaskConnections, dimensions=self.test_dims): + class TestConnections( + pipeBase.PipelineTaskConnections, + dimensions=self.test_dims, + defaultTemplates={"t1": "dataset_type_1"}, + deprecatedTemplates={"t1": "Deprecated in v600, will be removed after v601."}, + ): input1 = pipeBase.connectionTypes.Input( doc="Docs for input1", - name="input1_dataset_type", + name="input1_{t1}", storageClass="StructuredDataDict", deprecated="Deprecated in v50000, will be removed after v50001.", ) @@ -205,7 +210,9 @@ class TestConfig(pipeBase.PipelineTaskConfig, pipelineConnections=TestConnection config = TestConfig() with self.assertWarns(FutureWarning): - config.connections.input1 = "some_other_dataset_type" + config.connections.input1 = "dataset_type_2" + with self.assertWarns(FutureWarning): + config.connections.t1 = "dataset_type_3" with self.assertWarns(FutureWarning): TestConnections(config=config)