-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix(actors): Allow boolean-like values for SKIP_DRY #538
Conversation
def str2bool(self, v, strict=False): | ||
"""Returns a Boolean from a variety of inputs. | ||
|
||
Args: | ||
value: String/Bool | ||
strict: Whether or not to _only_ convert the known words into booleans, or whether to allow "any" word to be considered True other than the known False words. | ||
|
||
Returns: | ||
A boolean | ||
""" | ||
false = ("no", "false", "f", "0") | ||
true = ("yes", "true", "t", "1") | ||
|
||
string = str(v).lower() | ||
|
||
if strict: | ||
if string not in true and string not in false: | ||
raise exceptions.InvalidOptions( | ||
"Expected [%s, %s] but got: %s" % (true, false, string) | ||
) | ||
|
||
return string not in false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to kingpin.utils
for use in non-actor
classes.
def str2bool(v, strict=False) -> bool: | ||
"""Returns a Boolean from a variety of inputs. | ||
|
||
Args: | ||
value: String/Bool | ||
strict: Whether or not to _only_ convert the known words into booleans, or whether to allow "any" word to be considered True other than the known False words. | ||
|
||
Returns: | ||
A boolean | ||
""" | ||
false = ("no", "false", "f", "0") | ||
true = ("yes", "true", "t", "1") | ||
|
||
string = str(v).lower() | ||
|
||
if strict: | ||
if string not in true and string not in false: | ||
raise ValueError(f"Expected [{true}, {false}] but got: {string}") | ||
|
||
return string not in false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From deleted function above.
try: | ||
check = utils.str2bool(self._condition) | ||
self.log.debug("Condition %s evaluates to %s" % (self._condition, check)) | ||
except ValueError as e: | ||
raise exceptions.InvalidOptions(e.args) from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added try-except to convert the raised error to maintain correct raise types outside function.
Fixes a usability issue where regardless of the value of DRY, if SKIP_DRY was true you would get the following message:
The way the logic works after this PR is thusly...
(default)
- Run Wet 💦
(default)
- Run Wet 💦