Skip to content

Commit

Permalink
Normalize variables
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Nov 25, 2020
1 parent 3593c7c commit e980756
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions yt/utilities/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import sys

from yt.config import CURRENT_CONFIG_FILE, OLD_CONFIG_FILE, YTConfig
from yt.config import CURRENT_CONFIG_FILE, OLD_CONFIG_FILE, YTConfig, ytcfg_defaults

CONFIG = YTConfig()
CONFIG.read(CURRENT_CONFIG_FILE)
Expand Down Expand Up @@ -63,15 +63,24 @@ def migrate_config():
old_config.optionxform = str
old_config.read(OLD_CONFIG_FILE)

default_keys = {k.lower(): k for k in ytcfg_defaults["yt"].keys()}

config_as_dict = {}
for section in old_config:
if section == "DEFAULT":
continue
config_as_dict[section] = {}
for key, value in old_config[section].items():
config_as_dict[section][key] = _cast_value_helper(value)
# Cast value to the most specific type possible
cast_value = _cast_value_helper(value)

# Normalize the key (if present in the defaults)
if key.lower() in default_keys and section == "yt":
normalized_key = default_keys[key.lower()]
else:
normalized_key = key

print(config_as_dict)
config_as_dict[section][normalized_key] = cast_value

CONFIG.update(config_as_dict)

Expand Down
3 changes: 2 additions & 1 deletion yt/utilities/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from yt.config import CURRENT_CONFIG_FILE, OLD_CONFIG_FILE, YTConfig

_TEST_PLUGIN = "_test_plugin.py"
# NOTE: the normalization of the crazy camel-case will be checked
_DUMMY_CFG_INI = f"""[yt]
loglevel = 49
lOgLeVeL = 49
pluginFilename = {_TEST_PLUGIN}
booleanStuff = True
"""
Expand Down

0 comments on commit e980756

Please sign in to comment.