Skip to content

Commit

Permalink
Fix premature validation for properties.
Browse files Browse the repository at this point in the history
Properties should validate in _validate(), not in _set(), so that we can
get help, version info, etc. This appears to be the intent because
Executive.verifyConfiguration() will call _validate() and nicely prints
all of the errors, not just the first one.
  • Loading branch information
baagaard-usgs committed Jun 30, 2016
1 parent 09b1768 commit 183a459
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
20 changes: 5 additions & 15 deletions pyre/inventory/Configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,13 @@ def updateConfiguration(self, registry):
def applyConfiguration(self, context=None):
"""transfer user settings to my inventory"""

try:

if context is None:
context = self.newConfigContext()
if context is None:
context = self.newConfigContext()

context.configureComponent(self)
context.configureComponent(self)

# give descendants a chance to adjust to configuration changes
self._configure()


except ValueError, err:
aliases = ", ".join(self.aliases)
raise ValueError("%s\nBacktrace - Component %s" % (err.message, aliases))
except RuntimeError, err:
aliases = ", ".join(self.aliases)
raise RuntimeError("%s\nBacktrace - Component %s" % (err.message, aliases))
# give descendants a chance to adjust to configuration changes
self._configure()

return context

Expand Down
5 changes: 2 additions & 3 deletions pyre/inventory/Property.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def _getDefaultValue(self, instance):
if value is not None:
# convert
value = self._cast(value)
# validate
if self.validator:
value = self.validator(value)

import pyre.parsing.locators
locator = pyre.parsing.locators.default()
Expand All @@ -63,6 +60,8 @@ def _cast(self, input):


def _validate(self, value):
if self.validator:
value = self.validator(value)
return value


Expand Down

0 comments on commit 183a459

Please sign in to comment.