aboutsummaryrefslogtreecommitdiffstats
path: root/config_file
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
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')
-rw-r--r--config_file/config_file_path.py10
-rw-r--r--config_file/parsers/parse_value.py17
2 files changed, 18 insertions, 9 deletions
diff --git a/config_file/config_file_path.py b/config_file/config_file_path.py
index 0558faa..1daad7b 100644
--- a/config_file/config_file_path.py
+++ b/config_file/config_file_path.py
@@ -1,6 +1,5 @@
import os
-from pathlib import Path as _Path_
-from pathlib import _posix_flavour, _windows_flavour
+from pathlib import Path
from typing import Type
from config_file.parsers.abstract_parser import AbstractParser
@@ -12,19 +11,14 @@ from config_file.parsers.yaml_parser import YamlParser
from .utils import split_on_dot
-class ConfigFilePath(_Path_):
+class ConfigFilePath(type(Path())):
"""A ConfigFilePath object, which subclasses Path.
It provides us easy ways to grab the original config file
path, file extension, validate the path, or determine the parser
that should be use for the given file type.
-
- See https://codereview.stackexchange.com/questions/162426/subclassing-pathlib-path
- for more details on subclassing the pathlib.Path object.
"""
- _flavour = _windows_flavour if os.name == "nt" else _posix_flavour
-
@property
def original_path(self) -> "ConfigFilePath":
"""Computes the original configuration file path.
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.