Skip to content

Commit 6c5b526

Browse files
committed
Replace str_to_bool with a new implementation without deleted distutils dependency
1 parent 2c77239 commit 6c5b526

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

node_cli/utils/helper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
# You should have received a copy of the GNU Affero General Public License
1818
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1919

20-
import distutils
21-
import distutils.util
2220
import ipaddress
2321
import json
2422
import logging
@@ -145,8 +143,14 @@ def get_username():
145143
return os.environ.get('USERNAME') or os.environ.get('USER')
146144

147145

148-
def str_to_bool(val):
149-
return bool(distutils.util.strtobool(val))
146+
def str_to_bool(val: str) -> bool:
147+
val = val.lower()
148+
if val in ('y', 'yes', 't', 'true', 'on', '1'):
149+
return True
150+
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
151+
return False
152+
else:
153+
raise ValueError(f'Invalid truth value {val!r}')
150154

151155

152156
def error_exit(error_payload: Any, exit_code: CLIExitCodes = CLIExitCodes.FAILURE) -> NoReturn:

0 commit comments

Comments
 (0)