Team Ai
Datasetpublic

Benjamin-eecs/openrsi-commit-runtime-assets

sourceHugging Faceupdated 16d agoView on Hugging Face
0likes168downloads
patch.diff84 linesDownload Raw Back to solution
1diff --git a/CHANGELOG.md b/CHANGELOG.md2index 08025d9..d8e45a6 1006443--- a/CHANGELOG.md4+++ b/CHANGELOG.md5@@ -1,5 +1,12 @@6 # Changelog7 8+## unreleased9+10+Features:11+12+- Add `strip_whitespace` param to `FileAwareEnv` ([#431](https://github.com/sloria/environs/issues/431)).13+  Thanks [eandersons](https://github.com/eandersons) for the suggestion and PR.14+15 ## 14.4.0 (2025-10-29)16 17 Features:18diff --git a/README.md b/README.md19index a8d31e4..d5cb72e 10064420--- a/README.md21+++ b/README.md22@@ -350,7 +350,7 @@ file is found, its contents will be read and returned.23 ```python24 from environs import FileAwareEnv25 26-# echo 'my secret password' > /run/secrets/password27+# printf 'my secret password' >/run/secrets/password28 # export PASSWORD_FILE=/run/secrets/password29 30 env = FileAwareEnv()31@@ -362,13 +362,25 @@ It's also possible to set a different suffix for the variable names:32 ```python33 from environs import FileAwareEnv34 35-# echo 'my secret password' > /run/secrets/password36+# printf 'my secret password' >/run/secrets/password37 # export PASSWORD_SECRET=/run/secrets/password38 39 env = FileAwareEnv(file_suffix="_SECRET")40 password = env.str("PASSWORD")  #  => 'my secret password'41 ```42 43+To strip leading and trailing whitespaces from the value:44+45+```python46+from environs import FileAwareEnv47+48+# printf '  value with leading and trailing whitespaces \n' >/run/secrets/password49+# export PASSWORD_SECRET=/run/secrets/password50+51+env: FileAwareEnv = FileAwareEnv(strip_whitespace=True)52+password: str = env.str("PASSWORD")  # => `value with leading and trailing whitespaces`53+```54+55 ## Defining custom parser behavior56 57 ```python58diff --git a/src/environs/__init__.py b/src/environs/__init__.py59index f3ff8ba..555c763 10064460--- a/src/environs/__init__.py61+++ b/src/environs/__init__.py62@@ -584,8 +584,10 @@ class FileAwareEnv(Env):63         eager: _BoolType = True,64         expand_vars: _BoolType = False,65         prefix: _StrType | None = None,66+        strip_whitespace: _BoolType = False,67     ):68-        self.file_suffix = file_suffix69+        self.file_suffix: _StrType = file_suffix70+        self.strip_whitespace: _BoolType = strip_whitespace71         super().__init__(eager=eager, expand_vars=expand_vars, prefix=prefix)72 73     def _get_value(self, env_key: _StrType, default: typing.Any) -> typing.Any:74@@ -593,7 +595,8 @@ class FileAwareEnv(Env):75         file_key = f"{env_key}{self.file_suffix}"76         if file_path := os.environ.get(file_key, None):77             try:78-                return Path(file_path).read_text()79+                value: _StrType = Path(file_path).read_text()80+                return value.strip() if self.strip_whitespace else value81             except (FileNotFoundError, IsADirectoryError, PermissionError) as err:82                 raise ValueError(83                     f"The value of {file_key} must be a readable file path."84