speckenv 6.2__tar.gz → 6.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- speckenv-6.2/README.rst → speckenv-6.4.0/PKG-INFO +59 -2
- speckenv-6.2/PKG-INFO → speckenv-6.4.0/README.rst +36 -21
- {speckenv-6.2 → speckenv-6.4.0}/pyproject.toml +29 -28
- {speckenv-6.2 → speckenv-6.4.0}/speckenv_django.py +85 -22
- {speckenv-6.2 → speckenv-6.4.0}/.gitignore +0 -0
- {speckenv-6.2 → speckenv-6.4.0}/LICENSE +0 -0
- {speckenv-6.2 → speckenv-6.4.0}/speckenv.py +0 -0
- {speckenv-6.2 → speckenv-6.4.0}/speckenv_django_patch.py +0 -0
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: speckenv
|
|
3
|
+
Version: 6.4.0
|
|
4
|
+
Summary: Load environment from .env. Includes some optional Django goodies.
|
|
5
|
+
Project-URL: Homepage, https://github.com/matthiask/speckenv/
|
|
6
|
+
Author-email: Matthias Kestenholz <mk@feinheit.ch>
|
|
7
|
+
License: BSD-3-Clause
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/x-rst
|
|
23
|
+
|
|
1
24
|
========
|
|
2
25
|
speckenv
|
|
3
26
|
========
|
|
@@ -116,7 +139,11 @@ Covers configuring a Redis, locmem or dummy cache backend with optional
|
|
|
116
139
|
authentication credentials. The Redis configuration only supports Django 4 or
|
|
117
140
|
better. ``redis://`` and ``hiredis://`` are equivalent since recent enough
|
|
118
141
|
versions of redis-py automatically select the hiredis parser if it is
|
|
119
|
-
available.
|
|
142
|
+
available. Query string parameters other than ``key_prefix`` are passed on to
|
|
143
|
+
redis-py's connection pool; values are parsed using ``ast.literal_eval`` where
|
|
144
|
+
possible. Setting timeouts is a good idea, without them a request may hang for
|
|
145
|
+
a long time if the Redis server goes away without closing the connection:
|
|
146
|
+
``?socket_connect_timeout=2&socket_timeout=2&health_check_interval=30``.
|
|
120
147
|
|
|
121
148
|
.. code-block:: python
|
|
122
149
|
|
|
@@ -162,12 +189,42 @@ pass the return value to ``globals().update()``.
|
|
|
162
189
|
from speckenv import env
|
|
163
190
|
from speckenv_django import django_email_url
|
|
164
191
|
|
|
165
|
-
#
|
|
192
|
+
# EMAIL_URL=smtp://
|
|
166
193
|
if DEBUG:
|
|
167
194
|
globals().update(django_email_url(env("EMAIL_URL", default="console://")))
|
|
168
195
|
else:
|
|
169
196
|
globals().update(django_email_url(env("EMAIL_URL", default="smtp://")))
|
|
170
197
|
|
|
198
|
+
Django 6.1 deprecated the individual ``EMAIL_*`` settings in favor of the
|
|
199
|
+
``MAILERS`` dictionary; use ``django_mailer_url`` below instead when you're
|
|
200
|
+
using Django 6.1 or better.
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
``django_mailer_url``
|
|
204
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
205
|
+
|
|
206
|
+
Returns an entry for the ``MAILERS`` dictionary introduced in Django 6.1.
|
|
207
|
+
Supports the same URLs as ``django_email_url``, and additionally accepts
|
|
208
|
+
``?ssl_keyfile=...`` and ``?ssl_certfile=...``. ``SERVER_EMAIL`` isn't a part
|
|
209
|
+
of a mailer's configuration, so ``_server_email`` raises a ``ValueError``.
|
|
210
|
+
``_default_from_email`` is passed on as a ``default_from_email`` option; Django's
|
|
211
|
+
own backends reject it, but custom backends may support it. Use the ``backend``
|
|
212
|
+
keyword argument to select such a backend, e.g.
|
|
213
|
+
``django_mailer_url(url, backend="email_hosts.backends.EmailHostsBackend")``.
|
|
214
|
+
|
|
215
|
+
.. code-block:: python
|
|
216
|
+
|
|
217
|
+
from speckenv import env
|
|
218
|
+
from speckenv_django import django_mailer_url
|
|
219
|
+
|
|
220
|
+
# MAILER_URL=submission://user:password@smtp.example.com
|
|
221
|
+
MAILERS = {
|
|
222
|
+
"default": django_mailer_url(
|
|
223
|
+
env("MAILER_URL", default="console://" if DEBUG else "smtp://")
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL", default="webmaster@localhost")
|
|
227
|
+
|
|
171
228
|
|
|
172
229
|
Automatically substituting other Django 12factor libraries
|
|
173
230
|
==========================================================
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: speckenv
|
|
3
|
-
Version: 6.2
|
|
4
|
-
Project-URL: Homepage, https://github.com/matthiask/speckenv/
|
|
5
|
-
Author-email: Matthias Kestenholz <mk@feinheit.ch>
|
|
6
|
-
License: BSD-3-Clause
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Classifier: Intended Audience :: Developers
|
|
9
|
-
Classifier: License :: OSI Approved :: BSD License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: Programming Language :: Python
|
|
12
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
-
Requires-Python: >=3.9
|
|
18
|
-
Description-Content-Type: text/x-rst
|
|
19
|
-
|
|
20
1
|
========
|
|
21
2
|
speckenv
|
|
22
3
|
========
|
|
@@ -135,7 +116,11 @@ Covers configuring a Redis, locmem or dummy cache backend with optional
|
|
|
135
116
|
authentication credentials. The Redis configuration only supports Django 4 or
|
|
136
117
|
better. ``redis://`` and ``hiredis://`` are equivalent since recent enough
|
|
137
118
|
versions of redis-py automatically select the hiredis parser if it is
|
|
138
|
-
available.
|
|
119
|
+
available. Query string parameters other than ``key_prefix`` are passed on to
|
|
120
|
+
redis-py's connection pool; values are parsed using ``ast.literal_eval`` where
|
|
121
|
+
possible. Setting timeouts is a good idea, without them a request may hang for
|
|
122
|
+
a long time if the Redis server goes away without closing the connection:
|
|
123
|
+
``?socket_connect_timeout=2&socket_timeout=2&health_check_interval=30``.
|
|
139
124
|
|
|
140
125
|
.. code-block:: python
|
|
141
126
|
|
|
@@ -181,12 +166,42 @@ pass the return value to ``globals().update()``.
|
|
|
181
166
|
from speckenv import env
|
|
182
167
|
from speckenv_django import django_email_url
|
|
183
168
|
|
|
184
|
-
#
|
|
169
|
+
# EMAIL_URL=smtp://
|
|
185
170
|
if DEBUG:
|
|
186
171
|
globals().update(django_email_url(env("EMAIL_URL", default="console://")))
|
|
187
172
|
else:
|
|
188
173
|
globals().update(django_email_url(env("EMAIL_URL", default="smtp://")))
|
|
189
174
|
|
|
175
|
+
Django 6.1 deprecated the individual ``EMAIL_*`` settings in favor of the
|
|
176
|
+
``MAILERS`` dictionary; use ``django_mailer_url`` below instead when you're
|
|
177
|
+
using Django 6.1 or better.
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
``django_mailer_url``
|
|
181
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
182
|
+
|
|
183
|
+
Returns an entry for the ``MAILERS`` dictionary introduced in Django 6.1.
|
|
184
|
+
Supports the same URLs as ``django_email_url``, and additionally accepts
|
|
185
|
+
``?ssl_keyfile=...`` and ``?ssl_certfile=...``. ``SERVER_EMAIL`` isn't a part
|
|
186
|
+
of a mailer's configuration, so ``_server_email`` raises a ``ValueError``.
|
|
187
|
+
``_default_from_email`` is passed on as a ``default_from_email`` option; Django's
|
|
188
|
+
own backends reject it, but custom backends may support it. Use the ``backend``
|
|
189
|
+
keyword argument to select such a backend, e.g.
|
|
190
|
+
``django_mailer_url(url, backend="email_hosts.backends.EmailHostsBackend")``.
|
|
191
|
+
|
|
192
|
+
.. code-block:: python
|
|
193
|
+
|
|
194
|
+
from speckenv import env
|
|
195
|
+
from speckenv_django import django_mailer_url
|
|
196
|
+
|
|
197
|
+
# MAILER_URL=submission://user:password@smtp.example.com
|
|
198
|
+
MAILERS = {
|
|
199
|
+
"default": django_mailer_url(
|
|
200
|
+
env("MAILER_URL", default="console://" if DEBUG else "smtp://")
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL", default="webmaster@localhost")
|
|
204
|
+
|
|
190
205
|
|
|
191
206
|
Automatically substituting other Django 12factor libraries
|
|
192
207
|
==========================================================
|
|
@@ -6,11 +6,12 @@ requires = [
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "speckenv"
|
|
9
|
-
version = "6.
|
|
9
|
+
version = "6.4.0"
|
|
10
|
+
description = "Load environment from .env. Includes some optional Django goodies."
|
|
10
11
|
readme = "README.rst"
|
|
11
|
-
license = {text= "BSD-3-Clause"}
|
|
12
|
+
license = { text = "BSD-3-Clause" }
|
|
12
13
|
authors = [
|
|
13
|
-
|
|
14
|
+
{ name = "Matthias Kestenholz", email = "mk@feinheit.ch" },
|
|
14
15
|
]
|
|
15
16
|
requires-python = ">=3.9"
|
|
16
17
|
classifiers = [
|
|
@@ -23,21 +24,34 @@ classifiers = [
|
|
|
23
24
|
"Programming Language :: Python :: 3.10",
|
|
24
25
|
"Programming Language :: Python :: 3.11",
|
|
25
26
|
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
"Programming Language :: Python :: 3.15",
|
|
26
30
|
]
|
|
27
|
-
|
|
28
|
-
Homepage = "https://github.com/matthiask/speckenv/"
|
|
31
|
+
urls.Homepage = "https://github.com/matthiask/speckenv/"
|
|
29
32
|
|
|
30
|
-
[tool.hatch
|
|
31
|
-
include = [
|
|
33
|
+
[tool.hatch]
|
|
34
|
+
build.include = [
|
|
32
35
|
"speckenv.py",
|
|
33
36
|
"speckenv_django.py",
|
|
34
37
|
"speckenv_django_patch.py",
|
|
35
38
|
]
|
|
36
39
|
|
|
37
40
|
[tool.ruff]
|
|
41
|
+
target-version = "py39"
|
|
42
|
+
fix = true
|
|
43
|
+
show-fixes = true
|
|
44
|
+
extend-ignore = [
|
|
45
|
+
# Allow zip() without strict=
|
|
46
|
+
"B905",
|
|
47
|
+
# No line length errors
|
|
48
|
+
"E501",
|
|
49
|
+
]
|
|
38
50
|
extend-select = [
|
|
39
51
|
# pyflakes, pycodestyle
|
|
40
|
-
"F",
|
|
52
|
+
"F",
|
|
53
|
+
"E",
|
|
54
|
+
"W",
|
|
41
55
|
# mmcabe
|
|
42
56
|
"C90",
|
|
43
57
|
# isort
|
|
@@ -67,29 +81,16 @@ extend-select = [
|
|
|
67
81
|
# pygrep-hooks
|
|
68
82
|
"PGH",
|
|
69
83
|
# pylint
|
|
70
|
-
"PLC",
|
|
84
|
+
"PLC",
|
|
85
|
+
"PLE",
|
|
86
|
+
"PLW",
|
|
71
87
|
# unused noqa
|
|
72
88
|
"RUF100",
|
|
73
89
|
]
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"E501",
|
|
79
|
-
]
|
|
80
|
-
fix = true
|
|
81
|
-
show-fixes = true
|
|
82
|
-
target-version = "py39"
|
|
83
|
-
|
|
84
|
-
[tool.ruff.isort]
|
|
85
|
-
combine-as-imports = true
|
|
86
|
-
lines-after-imports = 2
|
|
87
|
-
|
|
88
|
-
[tool.ruff.mccabe]
|
|
89
|
-
max-complexity = 15
|
|
90
|
-
|
|
91
|
-
[tool.ruff.per-file-ignores]
|
|
92
|
-
"*/migrat*/*" = [
|
|
90
|
+
isort.combine-as-imports = true
|
|
91
|
+
isort.lines-after-imports = 2
|
|
92
|
+
mccabe.max-complexity = 15
|
|
93
|
+
per-file-ignores."*/migrat*/*" = [
|
|
93
94
|
# Allow using PascalCase model names in migrations
|
|
94
95
|
"N806",
|
|
95
96
|
# Ignore the fact that migration files are invalid module names
|
|
@@ -7,6 +7,7 @@ __all__ = [
|
|
|
7
7
|
"django_cache_url",
|
|
8
8
|
"django_database_url",
|
|
9
9
|
"django_email_url",
|
|
10
|
+
"django_mailer_url",
|
|
10
11
|
"django_storage_url",
|
|
11
12
|
]
|
|
12
13
|
|
|
@@ -44,7 +45,11 @@ def django_database_url(s, /):
|
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
def _redis_cache_url(url, qs):
|
|
47
|
-
|
|
48
|
+
# Everything except key_prefix is passed on to redis-py's connection pool,
|
|
49
|
+
# e.g. socket_timeout=2&health_check_interval=30&socket_keepalive=True
|
|
50
|
+
options = {
|
|
51
|
+
key: _try_eval(value) for key, value in qs.items() if key != "key_prefix"
|
|
52
|
+
}
|
|
48
53
|
if db := url.path.strip("/"):
|
|
49
54
|
options["db"] = db
|
|
50
55
|
|
|
@@ -91,35 +96,50 @@ INTERESTING_MAIL_BACKENDS = {
|
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
|
|
99
|
+
def _smtp_options(url, qs):
|
|
100
|
+
options = {
|
|
101
|
+
"host": url.hostname,
|
|
102
|
+
"port": url.port,
|
|
103
|
+
"username": _unquote(url.username or ""),
|
|
104
|
+
"password": _unquote(url.password or ""),
|
|
105
|
+
"use_tls": False,
|
|
106
|
+
"use_ssl": False,
|
|
107
|
+
"timeout": None,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if url.scheme == "smtp":
|
|
111
|
+
options["host"] = url.hostname or "localhost"
|
|
112
|
+
options["port"] = url.port or 25
|
|
113
|
+
if url.scheme == "submission":
|
|
114
|
+
options["use_tls"] = True
|
|
115
|
+
options["port"] = url.port or 587
|
|
116
|
+
if "ssl" in qs:
|
|
117
|
+
options["use_ssl"] = True
|
|
118
|
+
options["use_tls"] = False
|
|
119
|
+
if "tls" in qs:
|
|
120
|
+
options["use_ssl"] = False
|
|
121
|
+
options["use_tls"] = True
|
|
122
|
+
if timeout := qs.get("timeout"):
|
|
123
|
+
options["timeout"] = int(timeout)
|
|
124
|
+
return options
|
|
125
|
+
|
|
126
|
+
|
|
94
127
|
def django_email_url(s, /):
|
|
95
128
|
url = parse.urlparse(s)
|
|
96
129
|
qs = dict(parse.parse_qsl(url.query))
|
|
130
|
+
options = _smtp_options(url, qs)
|
|
97
131
|
|
|
98
132
|
config = {
|
|
99
133
|
"EMAIL_BACKEND": INTERESTING_MAIL_BACKENDS[url.scheme],
|
|
100
|
-
"EMAIL_HOST_USER":
|
|
101
|
-
"EMAIL_HOST_PASSWORD":
|
|
102
|
-
"EMAIL_HOST":
|
|
103
|
-
"EMAIL_PORT":
|
|
104
|
-
"EMAIL_TIMEOUT":
|
|
105
|
-
"EMAIL_USE_SSL":
|
|
106
|
-
"EMAIL_USE_TLS":
|
|
134
|
+
"EMAIL_HOST_USER": options["username"],
|
|
135
|
+
"EMAIL_HOST_PASSWORD": options["password"],
|
|
136
|
+
"EMAIL_HOST": options["host"],
|
|
137
|
+
"EMAIL_PORT": options["port"],
|
|
138
|
+
"EMAIL_TIMEOUT": options["timeout"],
|
|
139
|
+
"EMAIL_USE_SSL": options["use_ssl"],
|
|
140
|
+
"EMAIL_USE_TLS": options["use_tls"],
|
|
107
141
|
}
|
|
108
142
|
|
|
109
|
-
if url.scheme == "smtp":
|
|
110
|
-
config["EMAIL_HOST"] = url.hostname or "localhost"
|
|
111
|
-
config["EMAIL_PORT"] = url.port or 25
|
|
112
|
-
if url.scheme == "submission":
|
|
113
|
-
config["EMAIL_USE_TLS"] = True
|
|
114
|
-
config["EMAIL_PORT"] = url.port or 587
|
|
115
|
-
if "ssl" in qs:
|
|
116
|
-
config["EMAIL_USE_SSL"] = True
|
|
117
|
-
config["EMAIL_USE_TLS"] = False
|
|
118
|
-
if "tls" in qs:
|
|
119
|
-
config["EMAIL_USE_SSL"] = False
|
|
120
|
-
config["EMAIL_USE_TLS"] = True
|
|
121
|
-
if timeout := qs.get("timeout"):
|
|
122
|
-
config["EMAIL_TIMEOUT"] = int(timeout)
|
|
123
143
|
if email := qs.get("_default_from_email"):
|
|
124
144
|
config["DEFAULT_FROM_EMAIL"] = email
|
|
125
145
|
if email := qs.get("_server_email"):
|
|
@@ -127,6 +147,49 @@ def django_email_url(s, /):
|
|
|
127
147
|
return config
|
|
128
148
|
|
|
129
149
|
|
|
150
|
+
def _smtp_mailer_url(url, qs):
|
|
151
|
+
options = _smtp_options(url, qs)
|
|
152
|
+
for key in ("ssl_keyfile", "ssl_certfile"):
|
|
153
|
+
if value := qs.get(key):
|
|
154
|
+
options[key] = value
|
|
155
|
+
return {
|
|
156
|
+
"BACKEND": "django.core.mail.backends.smtp.EmailBackend",
|
|
157
|
+
"OPTIONS": options,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _optionless_mailer_url(backend):
|
|
162
|
+
return lambda url, qs: {"BACKEND": backend, "OPTIONS": {}}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
INTERESTING_MAILER_BACKENDS = {
|
|
166
|
+
"smtp": _smtp_mailer_url,
|
|
167
|
+
"submission": _smtp_mailer_url,
|
|
168
|
+
"locmem": _optionless_mailer_url("django.core.mail.backends.locmem.EmailBackend"),
|
|
169
|
+
"console": _optionless_mailer_url("django.core.mail.backends.console.EmailBackend"),
|
|
170
|
+
"dummy": _optionless_mailer_url("django.core.mail.backends.dummy.EmailBackend"),
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def django_mailer_url(s, /, *, backend=None):
|
|
175
|
+
url = parse.urlparse(s)
|
|
176
|
+
qs = dict(parse.parse_qsl(url.query))
|
|
177
|
+
|
|
178
|
+
if "_server_email" in qs:
|
|
179
|
+
raise ValueError(
|
|
180
|
+
"_server_email cannot be part of a MAILERS entry,"
|
|
181
|
+
" set SERVER_EMAIL separately."
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
config = INTERESTING_MAILER_BACKENDS[url.scheme](url, qs)
|
|
185
|
+
# Only supported by custom backends, Django rejects it otherwise
|
|
186
|
+
if email := qs.get("_default_from_email"):
|
|
187
|
+
config["OPTIONS"]["default_from_email"] = email
|
|
188
|
+
if backend:
|
|
189
|
+
config["BACKEND"] = backend
|
|
190
|
+
return config
|
|
191
|
+
|
|
192
|
+
|
|
130
193
|
def _file_storage_url(url, qs, *, base_dir):
|
|
131
194
|
return {
|
|
132
195
|
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|