Skip to content

Commit

Permalink
Remove deprecated settings implementation
Browse files Browse the repository at this point in the history
This removes the old settings module and renames setting2.py to
setting.py. This is a breaking change for plugins that were doing
something like `from armi.settings import setting2 as setting`, but
trivial to refactor around.
  • Loading branch information
youngmit committed Apr 16, 2020
1 parent 19e22d2 commit 9f0b552
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 1,687 deletions.
8 changes: 0 additions & 8 deletions armi/cli/entryPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import armi
from armi import settings
from armi.settings import setting
from armi import runLog


Expand Down Expand Up @@ -196,13 +195,6 @@ def createOptionFromSetting(
helpMessage = argparse.SUPPRESS
else:
helpMessage = settingsInstance.description.replace("%", "%%")
if isinstance(settingsInstance, setting.StrSetting):
if settingsInstance.enforcedOptions:
choices = settingsInstance.options
if settingsInstance.options:
helpMessage += " The standard choices are: {}".format(
", ".join(settingsInstance.options)
)

aliases = ["--" + settingName]
if additionalAlias is not None:
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/fuelCycle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from armi import operators
from armi.utils import directoryChangers
from armi.operators import RunTypes
from armi.settings import setting2 as setting
from armi.settings import setting
from armi.operators import settingsValidation

from armi.physics.fuelCycle import fuelHandlers
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/fuelPerformance/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Settings related to fuel performance."""

from armi.settings import setting2 as setting
from armi.settings import setting
from armi.operators.settingsValidation import Query


Expand Down
2 changes: 1 addition & 1 deletion armi/physics/neutronics/crossSectionSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"""
import voluptuous as vol

from armi.settings.setting2 import Setting
from armi.settings import Setting

from armi.physics.neutronics.crossSectionGroupManager import (
BLOCK_COLLECTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Settings related to the fission product model."""

from armi.settings import setting2 as setting
from armi.settings import setting


CONF_FP_MODEL = "fpModel"
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/neutronics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

"""Some generic neutronics-related settings."""
from armi.settings import setting2 as setting
from armi.settings import setting


CONF_NEUTRONICS_KERNEL = "neutronicsKernel"
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/safety/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from armi.settings import setting2 as setting
from armi.settings import setting


CONF_BETA_COMPONENTS = "betaComponents"
Expand Down
6 changes: 3 additions & 3 deletions armi/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def defineSettings():
See also
--------
armi.physics.neutronics.NeutronicsPlugin.defineSettings
armi.settings.setting2.Setting
armi.settings.setting2.Option
armi.settings.setting2.Default
armi.settings.setting.Setting
armi.settings.setting.Option
armi.settings.setting.Default
"""
return []
Expand Down
35 changes: 6 additions & 29 deletions armi/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@
They are one of the key inputs to an ARMI run. They say which modules to run and which
modeling approximations to apply and how many cycles to run and at what power and
availability fraction and things like that.
Notes
-----
Originally, these were just a Python module ``settings.py`` that had Python types in it.
We transitioned to XML because it was trendy. Later, we wanted better uniformity across
our input formats so we made it do YAML, too. We then added the ability to provide new
Settings from plugins, which introduced the ``setting2`` module. As a result of this
history, there are now two implementations of the ``Setting`` class, which, while they
are not related through inheritance, do expose very similar interfaces and can largely
be used interchangeably. There are no insances of the old ``Setting`` format, but we are
leaving it in the code for now to facilitate input migrations from older versions of
ARMI. We plan to remove the old implementation, and replace it with the new
implementation in ``setting2`` very soon.
availability fraction and things like that. The ARMI Framework itself has many settings
of its own, and plugins typically register some of their own settings as well.
"""
import fnmatch
import os
Expand All @@ -46,25 +34,14 @@
from armi.settings.caseSettings import Settings
from armi.utils import pathTools

from armi.settings.setting import Setting, BoolSetting
from armi.settings.setting2 import Setting as Setting2
from armi.settings.setting import Setting

NOT_ENABLED = "" # An empty setting value implies that the feature


def isBoolSetting(setting: Union[Setting, Setting2]) -> bool:
"""Return whether the passed setting represents a boolean value.
This is useful during the transition from old to new settings. The old settings used
to be "strongly" typed, wheras the new once are a little bit looser in that their
types are largely enforced by their schemas. In situations where we want to treat
bool-y settings special (e.g., when we want to make command-line toggles out of
them), this provides the appropriate logic depending on which Setting class is being
used.
"""
return isinstance(setting, BoolSetting) or (
isinstance(setting, Setting2) and isinstance(setting.default, bool)
)
def isBoolSetting(setting:Setting) -> bool:
"""Return whether the passed setting represents a boolean value."""
return isinstance(setting.default, bool)


def recursivelyLoadSettingsFiles(
Expand Down
26 changes: 9 additions & 17 deletions armi/settings/caseSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
from armi import runLog
from armi.localization import exceptions
from armi.settings import fwSettings
from armi.settings import setting
from armi.settings import settingsIO
from armi.utils import pathTools
from armi.settings import setting2
from armi.settings import setting


class Settings:
Expand Down Expand Up @@ -106,7 +105,7 @@ def _loadPluginSettings(self):

for pluginSettings in pm.hook.defineSettings():
for pluginSetting in pluginSettings:
if isinstance(pluginSetting, setting2.Setting):
if isinstance(pluginSetting, setting.Setting):
name = pluginSetting.name
if name in self.settings:
raise ValueError(
Expand All @@ -119,7 +118,7 @@ def _loadPluginSettings(self):
self.settings[name].addOptions(optionsCache.pop(name))
if name in defaultsCache:
self.settings[name].changeDefault(defaultsCache.pop(name))
elif isinstance(pluginSetting, setting2.Option):
elif isinstance(pluginSetting, setting.Option):
if pluginSetting.settingName in self.settings:
# modifier loaded after setting, so just apply it (no cache needed)
self.settings[pluginSetting.settingName].addOption(
Expand All @@ -128,7 +127,7 @@ def _loadPluginSettings(self):
else:
# no setting yet, cache it and apply when it arrives
optionsCache[pluginSetting.settingName].append(pluginSetting)
elif isinstance(pluginSetting, setting2.Default):
elif isinstance(pluginSetting, setting.Default):
if pluginSetting.settingName in self.settings:
# modifier loaded after setting, so just apply it (no cache needed)
self.settings[pluginSetting.settingName].changeDefault(
Expand Down Expand Up @@ -210,7 +209,7 @@ def __setstate__(self, state):
See Also
--------
armi.settings.setting2.Setting.__getstate__ : removes schema
armi.settings.setting.Setting.__getstate__ : removes schema
"""
self.settings = {}
self.loadAllDefaults()
Expand All @@ -222,15 +221,8 @@ def __setstate__(self, state):
setattr(self, key, val)
# with schema restored, restore all setting values
for name, settingState in state["settings"].items():
if isinstance(settingState, setting.Setting):
# old style. fully pickleable, restore entire setting object
self.settings[name] = settingState
else:
# new style, just restore value from dict.
# sorry about this being ugly.
self.settings[
name
]._value = settingState.value # pylint: disable=protected-access
# pylint: disable=protected-access
self.settings[name]._value = settingState.value

def keys(self):
return self.settings.keys()
Expand Down Expand Up @@ -337,8 +329,8 @@ def loadAllDefaults(self):
for dirname, _dirnames, filenames in os.walk(armi.RES):
for filename in filenames:
if filename.lower().endswith("settings.xml"):
reader = settingsIO.SettingsDefinitionReader(self)
reader.readFromFile(os.path.join(dirname, filename))
#KILLME
raise RuntimeError("Old settings are deprecated")

for fwSetting in fwSettings.getFrameworkSettings():
self.settings[fwSetting.name] = fwSetting
Expand Down
2 changes: 1 addition & 1 deletion armi/settings/fwSettings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
from typing import List

from armi.settings import setting2 as setting
from armi.settings import setting
from . import globalSettings
from . import xsSettings
from . import databaseSettings
Expand Down
2 changes: 1 addition & 1 deletion armi/settings/fwSettings/databaseSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Settings related to the ARMI database."""

from armi.settings import setting2 as setting
from armi.settings import setting


CONF_DB = "db"
Expand Down
2 changes: 1 addition & 1 deletion armi/settings/fwSettings/globalSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import voluptuous as vol

from armi import context
from armi.settings import setting2 as setting
from armi.settings import setting


# Framework settings
Expand Down
2 changes: 1 addition & 1 deletion armi/settings/fwSettings/reportSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Settings related to the report generation."""

from armi.settings import setting2 as setting
from armi.settings import setting


CONF_GEN_REPORTS = "genReports"
Expand Down
2 changes: 1 addition & 1 deletion armi/settings/fwSettings/xsSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Settings related to the cross section."""

from armi.settings import setting2 as setting
from armi.settings import setting


CONF_CLEAR_XS = "clearXS"
Expand Down

0 comments on commit 9f0b552

Please sign in to comment.