Skip to content

Commit

Permalink
Add support for deprecating connection templates.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TallJimbo committed Jul 5, 2023
1 parent 74ccb42 commit 641a18e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion python/lsst/pipe/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion python/lsst/pipe/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
Expand All @@ -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)
Expand Down

0 comments on commit 641a18e

Please sign in to comment.