Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-32594: Roll back BpsConfig changes that added dependence on inflection package. #76

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/changes/DM-32594.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rolled back changes in BpsConfig that were added for flexibility when looking up config values
(e.g., snake case keys will no longer match camel case keys nor will either match lower case keys).
This also removed dependence on third-party inflection package.
47 changes: 10 additions & 37 deletions python/lsst/ctrl/bps/bps_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import string
import re
from importlib.resources import path as resources_path
import inflection

from lsst.daf.butler.core.config import Config

Expand Down Expand Up @@ -161,38 +160,6 @@ def __contains__(self, name):
found, _ = self.search(name, {})
return found

@staticmethod
def _search_casing(sect, key):
# Until have more robust handling of key casing at config creation
# time, try checking here for different key casing.
found = False
value = ""

_LOG.debug("_search_casing: sect=%s key=%s", sect, key)
if Config.__contains__(sect, key):
found = True
value = Config.__getitem__(sect, key)
elif '_' in key:
newkey = inflection.camelize(key, False)
_LOG.debug("_search_casing: newkey=%s", newkey)
if Config.__contains__(sect, newkey):
found = True
value = Config.__getitem__(sect, newkey)
else: # try converting camel to snake
newkey = inflection.underscore(key)
_LOG.debug("_search_casing: newkey=%s", newkey)
if Config.__contains__(sect, newkey):
found = True
value = Config.__getitem__(sect, newkey)
else: # Try all lower case
newkey = key.lower()
_LOG.debug("_search_casing: newkey=%s", newkey)
if Config.__contains__(sect, newkey):
found = True
value = Config.__getitem__(sect, newkey)

return found, value

def search(self, key, opt=None):
"""Search for key using given opt following hierarchy rules.

Expand Down Expand Up @@ -281,15 +248,21 @@ def search(self, key, opt=None):
if Config.__contains__(search_sect, currkey):
search_sect = Config.__getitem__(search_sect, currkey)

found, value = self._search_casing(search_sect, key)
if found:
_LOG.debug("%s %s", key, search_sect)
if Config.__contains__(search_sect, key):
found = True
value = Config.__getitem__(search_sect, key)
break
else:
_LOG.debug("Missing search section '%s' while searching for '%s'", sect, key)

# lastly check root values
if not found:
_LOG.debug("Searching root section for key '%s'", key)
found, value = self._search_casing(self, key)
_LOG.debug(" root found=%s, value='%s'", found, value)
if Config.__contains__(self, key):
found = True
value = Config.__getitem__(self, key)
_LOG.debug("root value='%s'", value)

if not found and "default" in opt:
value = opt["default"]
Expand Down
4 changes: 3 additions & 1 deletion python/lsst/ctrl/bps/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ def _get_job_values(config, search_opt, cmd_line_key):
"""
job_values = {}
for attr in _ATTRS_ALL:
found, value = config.search(attr, opt=search_opt)
# Variable names in yaml are camel case instead of snake case.
yaml_name = re.sub(r"_(\S)", lambda match: match.group(1).upper(), attr)
found, value = config.search(yaml_name, opt=search_opt)
if found:
job_values[attr] = value
else:
Expand Down