Skip to content

Commit

Permalink
Merge pull request #4477 from bartoldeman/remove-strtobool
Browse files Browse the repository at this point in the history
Eliminate `distutils.util.strtobool`.
  • Loading branch information
branfosj committed Mar 7, 2024
2 parents 82c8516 + bce95ec commit 27aab7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions easybuild/framework/easyconfig/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Caroline De Brouwer (Ghent University)
* Kenneth Hoste (Ghent University)
"""
from distutils.util import strtobool

from easybuild.base import fancylogger
from easybuild.framework.easyconfig.format.format import DEPENDENCY_PARAMETERS
Expand Down Expand Up @@ -280,7 +279,14 @@ def to_toolchain_dict(spec):
res = {'name': spec[0].strip(), 'version': spec[1].strip()}
# 3-element list
elif len(spec) == 3:
res = {'name': spec[0].strip(), 'version': spec[1].strip(), 'hidden': strtobool(spec[2].strip())}
hidden = spec[2].strip().lower()
if hidden in {'yes', 'true', 't', 'y', '1', 'on'}:
hidden = True
elif hidden in {'no', 'false', 'f', 'n', '0', 'off'}:
hidden = False
else:
raise EasyBuildError("Invalid truth value %s", hidden)
res = {'name': spec[0].strip(), 'version': spec[1].strip(), 'hidden': hidden}
else:
raise EasyBuildError("Can not convert list %s to toolchain dict. Expected 2 or 3 elements", spec)

Expand Down
6 changes: 3 additions & 3 deletions test/framework/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def test_to_toolchain_dict(self):
self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, ['gcc', '4', 'False', '7'])

# invalid truth value
errstr = "invalid truth value .*"
self.assertErrorRegex(ValueError, errstr, to_toolchain_dict, "intel, 2015, foo")
self.assertErrorRegex(ValueError, errstr, to_toolchain_dict, ['gcc', '4', '7'])
errstr = "Invalid truth value .*"
self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, "intel, 2015, foo")
self.assertErrorRegex(EasyBuildError, errstr, to_toolchain_dict, ['gcc', '4', '7'])

# missing keys
self.assertErrorRegex(EasyBuildError, "Incorrect set of keys", to_toolchain_dict, {'name': 'intel'})
Expand Down

0 comments on commit 27aab7c

Please sign in to comment.