Skip to content

Commit

Permalink
Merge pull request #77 from lsst/tickets/DM-32759
Browse files Browse the repository at this point in the history
DM-32759: Remove support for the old "root" in config files
  • Loading branch information
timj committed Jun 22, 2022
2 parents cc71245 + 9406455 commit 0bb880f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
31 changes: 2 additions & 29 deletions python/lsst/pex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,6 @@ def load(self, filename, root="config"):
Then this config's field ``myField`` is set to ``5``.
**Deprecated:** For backwards compatibility, older config files
that use ``root="root"`` instead of ``root="config"`` will be
loaded with a warning printed to `sys.stderr`. This feature will be
removed at some point.
See also
--------
lsst.pex.config.Config.loadFromStream
Expand Down Expand Up @@ -1033,11 +1028,6 @@ def loadFromStream(self, stream, root="config", filename=None):
config.myField = 5
Then this config's field ``myField`` is set to ``5``.
**Deprecated:** For backwards compatibility, older config files
that use ``root="root"`` instead of ``root="config"`` will be
loaded with a warning printed to `sys.stderr`. This feature will be
removed at some point.
filename : `str`, optional
Name of the configuration file, or `None` if unknown or contained
in the stream. Used for error reporting.
Expand Down Expand Up @@ -1082,11 +1072,6 @@ def loadFromString(self, code, root="config", filename=None):
config.myField = 5
Then this config's field ``myField`` is set to ``5``.
**Deprecated:** For backwards compatibility, older config files
that use ``root="root"`` instead of ``root="config"`` will be
loaded with a warning printed to `sys.stderr`. This feature will be
removed at some point.
filename : `str`, optional
Name of the configuration file, or `None` if unknown or contained
in the stream. Used for error reporting.
Expand All @@ -1105,20 +1090,8 @@ def loadFromString(self, code, root="config", filename=None):
filename = getattr(code, "co_filename", "?")
with RecordingImporter() as importer:
globals = {"__file__": filename}
try:
local = {root: self}
exec(code, globals, local)
except NameError as e:
if root == "config" and "root" in e.args[0]:
print(
f"Config override file {filename!r}"
" appears to use 'root' instead of 'config'; trying with 'root'",
file=sys.stderr,
)
local = {"root": self}
exec(code, globals, local)
else:
raise
local = {root: self}
exec(code, globals, local)

self._imports.update(importer.getModules())

Expand Down
7 changes: 4 additions & 3 deletions tests/test_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,13 @@ def testSave(self):
self.assertEqual(self.comp.r.name, roundTrip.r.name)
del roundTrip

# test backwards compatibility feature of allowing "root" instead of
# "config"
# Test an override of the default variable name.
with open("roundtrip.test", "w") as outfile:
self.comp.saveToStream(outfile, root="root")
roundTrip = Complex()
roundTrip.load("roundtrip.test")
with self.assertRaises(NameError):
roundTrip.load("roundtrip.test")
roundTrip.load("roundtrip.test", root="root")
os.remove("roundtrip.test")
self.assertEqual(self.comp.c.f, roundTrip.c.f)
self.assertEqual(self.comp.r.name, roundTrip.r.name)
Expand Down

0 comments on commit 0bb880f

Please sign in to comment.