Skip to content

Commit 80de46a

Browse files
authored
Remove variable proxying (#181)
close #175
1 parent 9c26d4a commit 80de46a

5 files changed

Lines changed: 6 additions & 80 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 9.0.0 (unreleased)
44

5+
- _Backwards-incompatible_: Remove variable proxying. Use variable expansion instead (see 8.1.0 release notes below)
6+
([#175](https://github.com/sloria/environs/issues/175)).
57
- _Backwards-incompatible_: Drop support for marshmallow 2 and Python 3.5,
68
which are both EOL ([#174](https://github.com/sloria/environs/issues/174)).
79

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ It allows you to store configuration separate from your code, as per
1818
- [Reading .env files](#reading-env-files)
1919
- [Reading a specific file](#reading-a-specific-file)
2020
- [Handling prefixes](#handling-prefixes)
21-
- [Proxied variables](#proxied-variables)
2221
- [Variable expansion](#variable-expansion)
2322
- [Validation](#validation)
2423
- [Deferred validation](#deferred-validation)
@@ -184,17 +183,6 @@ connection_url = env("CONNECTION_URL") # =>'https://sloria:secret@localhost'
184183
year = env.int("YEAR") # =>2020
185184
```
186185

187-
## Proxied variables
188-
189-
**Deprecated: use [Variable expansion](#variable-expansion) instead of proxied variables.**
190-
191-
```python
192-
# export MAILGUN_LOGIN=sloria
193-
# export SMTP_LOGIN={{MAILGUN_LOGIN}}
194-
195-
smtp_login = env("SMTP_LOGIN") # =>'sloria'
196-
```
197-
198186
## Validation
199187

200188
```python
@@ -420,7 +408,7 @@ environs will help you
420408
- validate envvars
421409
- parse list and dict values
422410
- parse dates, datetimes, and timedeltas
423-
- parse proxied variables
411+
- parse expanded variables
424412
- serialize your configuration to JSON, YAML, etc.
425413

426414
### Why another library?

environs/__init__.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import re
99
import typing
1010
import types
11-
import warnings
1211
from collections.abc import Mapping
1312
from urllib.parse import urlparse, ParseResult
1413
from pathlib import Path
@@ -20,8 +19,6 @@
2019
__version__ = "8.1.0"
2120
__all__ = ["EnvError", "Env"]
2221

23-
_PROXIED_PATTERN = re.compile(r"\s*{{\s*(\S*)\s*}}\s*")
24-
_EXPANDED_VAR_PATTERN = re.compile(r"(?<!\\)\$\{([A-Za-z0-9_]+)(:-[^\}:]*)?\}")
2522

2623
_T = typing.TypeVar("_T")
2724
_StrType = str
@@ -37,6 +34,9 @@
3734
ParserMethod = typing.Callable[..., typing.Union[_T, _Missing]]
3835

3936

37+
_EXPANDED_VAR_PATTERN = re.compile(r"(?<!\\)\$\{([A-Za-z0-9_]+)(:-[^\}:]*)?\}")
38+
39+
4040
class EnvError(ValueError):
4141
"""Raised when an environment variable or if a required environment variable is unset."""
4242

@@ -51,10 +51,6 @@ class EnvSealedError(TypeError, EnvError):
5151
pass
5252

5353

54-
class RemovedInEnvirons9Warning(DeprecationWarning):
55-
pass
56-
57-
5854
class ParserConflictError(ValueError):
5955
"""Raised when adding a custom parser that conflicts with a built-in parser method."""
6056

@@ -411,16 +407,6 @@ def _get_from_environ(
411407
env_key = self._get_key(key, omit_prefix=proxied)
412408
value = os.environ.get(env_key, default)
413409
if hasattr(value, "strip"):
414-
# TODO: Remove proxying in environs 9
415-
proxy_match = _PROXIED_PATTERN.match(value)
416-
if proxy_match: # Proxied variable
417-
proxied_key = proxy_match.groups()[0]
418-
warnings.warn(
419-
"Proxied variables are deprecated and will be removed in environs 9. "
420-
"Use variable expansion instead: ${{{proxied_key}}}".format(proxied_key=proxied_key),
421-
RemovedInEnvirons9Warning,
422-
)
423-
return (key, self._get_from_environ(proxied_key, default, proxied=True)[1], proxied_key)
424410
expand_match = self.expand_vars and _EXPANDED_VAR_PATTERN.match(value)
425411
if expand_match: # Full match expand_vars - special case keep default
426412
proxied_key = expand_match.groups()[0]

tests/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ ignored
33
STRING=foo
44
BOOL=true
55
LIST=wat,wer,wen
6-
PROXIED={{STRING}}
76
EXPANDED=${STRING}

tests/test_environs.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -201,53 +201,6 @@ def test_invalid_url(self, url, set_env, env):
201201
assert 'Environment variable "URL" invalid' in excinfo.value.args[0]
202202

203203

204-
class TestProxiedVariables:
205-
def test_reading_proxied_variable(self, set_env, env):
206-
set_env(
207-
{
208-
"MAILGUN_SMTP_LOGIN": "sloria",
209-
"SMTP_LOGIN": "{{MAILGUN_SMTP_LOGIN}}",
210-
"SMTP_LOGIN_LPADDED": "{{ MAILGUN_SMTP_LOGIN}}",
211-
"SMTP_LOGIN_RPADDED": "{{MAILGUN_SMTP_LOGIN }}",
212-
}
213-
)
214-
assert env("MAILGUN_SMTP_LOGIN") == "sloria"
215-
assert env.dump()["MAILGUN_SMTP_LOGIN"] == "sloria"
216-
for key in ("SMTP_LOGIN", "SMTP_LOGIN_LPADDED", "SMTP_LOGIN_RPADDED"):
217-
with pytest.warns(DeprecationWarning, match="Proxied variables are deprecated"):
218-
assert env(key) == "sloria"
219-
assert env.dump()[key] == "sloria"
220-
221-
def test_reading_missing_proxied_variable(self, set_env, env):
222-
set_env({"SMTP_LOGIN": "{{MAILGUN_SMTP_LOGIN}}"})
223-
with pytest.raises(environs.EnvError) as excinfo:
224-
with pytest.warns(DeprecationWarning, match="Proxied variables are deprecated"):
225-
env("SMTP_LOGIN")
226-
assert excinfo.value.args[0] == 'Environment variable "MAILGUN_SMTP_LOGIN" not set'
227-
with pytest.warns(DeprecationWarning, match="Proxied variables are deprecated"):
228-
assert env("SMTP_LOGIN", "default") == "default"
229-
230-
def test_reading_proxied_variable_in_prefix_scope(self, set_env, env):
231-
set_env(
232-
{
233-
"MAILGUN_SMTP_LOGIN": "szabolcs",
234-
"SMTP_LOGIN": "{{MAILGUN_SMTP_LOGIN}}",
235-
"SMTP_PASSWORD": "secret",
236-
"SMTP_NESTED_LOGIN": "{{SMTP_LOGIN}}",
237-
"SMTP_NESTED_PASSWORD": "nested-secret",
238-
}
239-
)
240-
241-
with env.prefixed("SMTP_"):
242-
with pytest.warns(DeprecationWarning, match="Proxied variables are deprecated"):
243-
assert env.str("LOGIN") == "szabolcs"
244-
assert env.str("PASSWORD") == "secret"
245-
with env.prefixed("NESTED_"):
246-
with pytest.warns(DeprecationWarning, match="Proxied variables are deprecated"):
247-
assert env.str("LOGIN") == "szabolcs"
248-
assert env.str("PASSWORD") == "nested-secret"
249-
250-
251204
class TestEnvFileReading:
252205
def test_read_env(self, env):
253206
if "STRING" in os.environ:
@@ -256,8 +209,6 @@ def test_read_env(self, env):
256209
env.read_env()
257210
assert env("STRING") == "foo"
258211
assert env.list("LIST") == ["wat", "wer", "wen"]
259-
with pytest.warns(DeprecationWarning, match="Proxied variables are deprecated"):
260-
assert env("PROXIED") == "foo"
261212
assert env("EXPANDED") == "foo"
262213

263214
# Regression test for https://github.com/sloria/environs/issues/96

0 commit comments

Comments
 (0)