aboutsummaryrefslogtreecommitdiffstats
path: root/config_file/parsers/parse_value.py
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2023-11-05 14:30:28 -0500
committerGitHub <noreply@github.com>2023-11-05 14:30:28 -0500
commitfa90fbae0cc329e6dd6a86b8254a09e2b25cf65d (patch)
tree8e02bc97ec5b7fad3a9966bea4c73434fcdbbd05 /config_file/parsers/parse_value.py
parentAdd todos for nested_lookup (diff)
downloadconfig-file-fa90fbae0cc329e6dd6a86b8254a09e2b25cf65d.zip
Fix GitHub Action Workflows and Add Support for Newer Python Versions (#29)
* Use ubuntu 20 instead of latest * Add python 3.10, 3.11, and 3.12 * Update action versions and use poetry cache * Install poetry before using cache * Use matrix for different os versions * Fix mypy install failure * Fix pathlib subclassing and strtobool distutils deprecation * Pin poetry in CI to 1.7.0 * Remove 3.11 and 3.12 temporarily * Add 3.11 * Add coverage.xml to gitignore * Only run 3.11 temporarily * Temp test command change * Use cov report * Show files * Use newer pytest versions for newer python versions * Try using 3.12 * Tweak command * Test using coverage directly * Use poetry run * Fix typo * Add back other python versions * Remove test_ci task * Add changelog entry
Diffstat (limited to 'config_file/parsers/parse_value.py')
-rw-r--r--config_file/parsers/parse_value.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/config_file/parsers/parse_value.py b/config_file/parsers/parse_value.py
index 12032d6..b324a4b 100644
--- a/config_file/parsers/parse_value.py
+++ b/config_file/parsers/parse_value.py
@@ -1,7 +1,6 @@
"""This module allows you to parse a string into its native type."""
import ast
import re
-from distutils.util import strtobool
from typing import Any
@@ -149,6 +148,22 @@ def can_be_parsed_as_bool(value: Any) -> bool:
return value == "true" or value == "false"
+# distutils strtobool backport: https://github.com/yukinarit/strtobool
+def strtobool(val):
+ """Convert a string representation of truth to true (1) or false (0).
+ True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
+ are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
+ 'val' is anything else.
+ """
+ val = val.lower()
+ if val in ('y', 'yes', 't', 'true', 'on', '1'):
+ return 1
+ elif val in ('n', 'no', 'f', 'false', 'off', '0'):
+ return 0
+ else:
+ raise ValueError("invalid truth value %r" % (val,))
+
+
def can_be_parsed_as_dict(value: Any) -> bool:
"""Checks whether a value can be parsed as a dictionary.