From 3e4f15aed4f3498bdcc02a465b189aeb14992bb9 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Tue, 29 Oct 2024 14:57:36 -0400 Subject: [PATCH] Support underscore as first char in env file variable names (#263) --- HISTORY.rst | 19 +++++++++++++++++-- src/everett/manager.py | 2 +- tests/data/.env | 4 ++++ tests/test_manager.py | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 2bad241..f0c5648 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,16 +1,31 @@ History ======= +3.4.0 (in development) +---------------------- + +Backwards incompatible changes: + +* Drop support for Python 3.8. Thanks, Rob! + +Fixes and features: + +* Add support for Python 3.13. (#260) Thanks, Rob! + +* Add support for underscore as first character in variable names in env files. + (#263) + + 3.3.0 (November 6th, 2023) -------------------------- Backwards incompatible changes: -* Dropped support for Python 3.7. (#220) +* Drop support for Python 3.7. (#220) Fixes and features: -* Added support for Python 3.12 (#221) +* Add support for Python 3.12 (#221) * Fix env file parsing in regards to quotes. (#230) diff --git a/src/everett/manager.py b/src/everett/manager.py index 381c3a1..dac4b48 100644 --- a/src/everett/manager.py +++ b/src/everett/manager.py @@ -55,7 +55,7 @@ # Regex for valid keys in an env file -ENV_KEY_RE = re.compile(r"^[a-z][a-z0-9_]*$", flags=re.IGNORECASE) +ENV_KEY_RE = re.compile(r"^[a-z_][a-z0-9_]*$", flags=re.IGNORECASE) logger = logging.getLogger("everett") diff --git a/tests/data/.env b/tests/data/.env index 3704799..795105b 100755 --- a/tests/data/.env +++ b/tests/data/.env @@ -3,4 +3,8 @@ LOGLEVEL=walter DEBUG=True YOURE_NOT_A=golfer +# env var with quotes around value DATABASE_URL="sqlite:///kahlua.db" + +# env var that starts with underscore +_TYPER_STANDARD_TRACEBACK=1 diff --git a/tests/test_manager.py b/tests/test_manager.py index f400a22..8f6dd38 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -372,12 +372,14 @@ def test_ConfigEnvFileEnv(datadir): assert cefe.get("not_a", namespace="youre") == "golfer" assert cefe.get("loglevel") == "walter" assert cefe.get("LOGLEVEL") == "walter" + assert cefe.get("_typer_standard_traceback") == "1" assert cefe.get("missing") is NO_VALUE assert cefe.data == { "LOGLEVEL": "walter", "DEBUG": "True", "YOURE_NOT_A": "golfer", "DATABASE_URL": "sqlite:///kahlua.db", + "_TYPER_STANDARD_TRACEBACK": "1", } cefe = ConfigEnvFileEnv(env_filename)