From 54daf88e3d0a146acf9b941784535600e5d2bbce Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 30 Aug 2023 15:40:54 +0200 Subject: [PATCH 01/40] Bump version --- CHANGELOG.rst | 6 ++++++ environ/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6f311d97..ca5f1da6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. +`v0.12.0`_ - 00-Unreleased-2023 +------------------------------- + + + `v0.11.1`_ - 30-August-2023 --------------------------- Fixed @@ -380,6 +385,7 @@ Added - Initial release. +.. _v0.12.0: https://github.com/joke2k/django-environ/compare/v0.11.1...develop .. _v0.11.1: https://github.com/joke2k/django-environ/compare/v0.11.0...v0.11.1 .. _v0.11.0: https://github.com/joke2k/django-environ/compare/v0.10.0...v0.11.0 .. _v0.10.0: https://github.com/joke2k/django-environ/compare/v0.9.0...v0.10.0 diff --git a/environ/__init__.py b/environ/__init__.py index 38b5b6dc..e7abf230 100644 --- a/environ/__init__.py +++ b/environ/__init__.py @@ -21,7 +21,7 @@ __copyright__ = 'Copyright (C) 2013-2022 Daniele Faraglia' """The copyright notice of the package.""" -__version__ = '0.11.1' +__version__ = '0.12.0' """The version of the package.""" __license__ = 'MIT' From b343e05ac696854bbb479e10395abde9d0e1f243 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 1 Sep 2023 10:16:40 +0200 Subject: [PATCH 02/40] Revert "Add variable expansion (fix #421)" This reverts commit c61bfb070c4704eb2e3049c0eb153bbff20e5c0e. --- CHANGELOG.rst | 7 +++-- docs/quickstart.rst | 22 -------------- environ/environ.py | 66 ++++++++-------------------------------- tests/test_expansion.py | 27 ---------------- tests/test_expansion.txt | 9 ------ 5 files changed, 17 insertions(+), 114 deletions(-) delete mode 100755 tests/test_expansion.py delete mode 100755 tests/test_expansion.txt diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ca5f1da6..a3a7806a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,7 +7,10 @@ and this project adheres to `Semantic Versioning `_. `v0.11.1`_ - 30-August-2023 @@ -402,4 +405,4 @@ Added .. _v0.4.1: https://github.com/joke2k/django-environ/compare/v0.4...v0.4.1 .. _v0.4: https://github.com/joke2k/django-environ/compare/v0.3.1...v0.4 .. _v0.3.1: https://github.com/joke2k/django-environ/compare/v0.3...v0.3.1 -.. _v0.3: https://github.com/joke2k/django-environ/compare/v0.2.1...v0.3 +.. _v0.3: https://github.com/joke2k/django-environ/compare/v0.2.1...v0.3 \ No newline at end of file diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 2ab100fd..62473838 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -23,28 +23,6 @@ And use it with ``settings.py`` as follows: :start-after: -code-begin- :end-before: -overview- -Variables can contain references to another variables: ``$VAR`` or ``${VAR}``. -Referenced variables are searched in the environment and within all definitions -in the ``.env`` file. References are checked for recursion (self-reference). -Exception is thrown if any reference results in infinite loop on any level -of recursion. Variable values are substituted similar to shell parameter -expansion. Example: - -.. code-block:: shell - - # shell - export POSTGRES_USERNAME='user' POSTGRES_PASSWORD='SECRET' - -.. code-block:: shell - - # .env - POSTGRES_HOSTNAME='example.com' - POSTGRES_DB='database' - DATABASE_URL="postgres://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOSTNAME}:5432/${POSTGRES_DB}" - -The value of ``DATABASE_URL`` variable will become -``postgres://user:SECRET@example.com:5432/database``. - The ``.env`` file should be specific to the environment and not checked into version control, it is best practice documenting the ``.env`` file with an example. For example, you can also add ``.env.dist`` with a template of your variables to diff --git a/environ/environ.py b/environ/environ.py index 644286e1..f74884be 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -17,9 +17,7 @@ import os import re import sys -import threading import warnings -from os.path import expandvars from urllib.parse import ( parse_qs, ParseResult, @@ -42,9 +40,6 @@ Openable = (str, os.PathLike) logger = logging.getLogger(__name__) -# Variables which values should not be expanded -NOT_EXPANDED = 'DJANGO_SECRET_KEY', 'CACHE_URL' - def _cast(value): # Safely evaluate an expression node or a string containing a Python @@ -194,11 +189,7 @@ class Env: for s in ('', 's')] CLOUDSQL = 'cloudsql' - VAR = re.compile(r'(?[A-Z_][0-9A-Z_]*)}?', - re.IGNORECASE) - def __init__(self, **scheme): - self._local = threading.local() self.smart_cast = True self.escape_proxy = False self.prefix = "" @@ -352,13 +343,9 @@ def path(self, var, default=NOTSET, **kwargs): """ return Path(self.get_value(var, default=default), **kwargs) - def get_value(self, var, cast=None, # pylint: disable=R0913 - default=NOTSET, parse_default=False, add_prefix=True): + def get_value(self, var, cast=None, default=NOTSET, parse_default=False): """Return value for given environment variable. - - Expand variables referenced as ``$VAR`` or ``${VAR}``. - - Detect infinite recursion in expansion (self-reference). - :param str var: Name of variable. :param collections.abc.Callable or None cast: @@ -367,33 +354,15 @@ def get_value(self, var, cast=None, # pylint: disable=R0913 If var not present in environ, return this instead. :param bool parse_default: Force to parse default. - :param bool add_prefix: - Whether to add prefix to variable name. :returns: Value from environment or default (if set). :rtype: typing.IO[typing.Any] """ - var_name = f'{self.prefix}{var}' if add_prefix else var - if not hasattr(self._local, 'vars'): - self._local.vars = set() - if var_name in self._local.vars: - error_msg = f"Environment variable '{var_name}' recursively "\ - "references itself (eventually)" - raise ImproperlyConfigured(error_msg) - - self._local.vars.add(var_name) - try: - return self._get_value( - var_name, cast=cast, default=default, - parse_default=parse_default) - finally: - self._local.vars.remove(var_name) - - def _get_value(self, var_name, cast=None, default=NOTSET, - parse_default=False): + logger.debug( "get '%s' casted as '%s' with default '%s'", - var_name, cast, default) + var, cast, default) + var_name = f'{self.prefix}{var}' if var_name in self.scheme: var_info = self.scheme[var_name] @@ -419,37 +388,26 @@ def _get_value(self, var_name, cast=None, default=NOTSET, value = self.ENVIRON[var_name] except KeyError as exc: if default is self.NOTSET: - error_msg = f'Set the {var_name} environment variable' + error_msg = f'Set the {var} environment variable' raise ImproperlyConfigured(error_msg) from exc value = default - # Expand variables - if isinstance(value, (bytes, str)) and var_name not in NOT_EXPANDED: - def repl(match_): - return self.get_value( - match_.group('name'), cast=cast, default=default, - parse_default=parse_default, add_prefix=False) - - is_bytes = isinstance(value, bytes) - if is_bytes: - value = value.decode('utf-8') - value = self.VAR.sub(repl, value) - value = expandvars(value) - if is_bytes: - value = value.encode('utf-8') - # Resolve any proxied values prefix = b'$' if isinstance(value, bytes) else '$' escape = rb'\$' if isinstance(value, bytes) else r'\$' + if hasattr(value, 'startswith') and value.startswith(prefix): + value = value.lstrip(prefix) + value = self.get_value(value, cast=cast, default=default) if self.escape_proxy and hasattr(value, 'replace'): value = value.replace(escape, prefix) # Smart casting - if self.smart_cast and cast is None and default is not None \ - and not isinstance(default, NoValue): - cast = type(default) + if self.smart_cast: + if cast is None and default is not None and \ + not isinstance(default, NoValue): + cast = type(default) value = None if default is None and value == '' else value diff --git a/tests/test_expansion.py b/tests/test_expansion.py deleted file mode 100755 index 757ee9a2..00000000 --- a/tests/test_expansion.py +++ /dev/null @@ -1,27 +0,0 @@ -import pytest - -from environ import Env, Path -from environ.compat import ImproperlyConfigured - - -class TestExpansion: - def setup_method(self, method): - Env.ENVIRON = {} - self.env = Env() - self.env.read_env(Path(__file__, is_file=True)('test_expansion.txt')) - - def test_expansion(self): - assert self.env('HELLO') == 'Hello, world!' - - def test_braces(self): - assert self.env('BRACES') == 'Hello, world!' - - def test_recursion(self): - with pytest.raises(ImproperlyConfigured) as excinfo: - self.env('RECURSIVE') - assert str(excinfo.value) == "Environment variable 'RECURSIVE' recursively references itself (eventually)" - - def test_transitive(self): - with pytest.raises(ImproperlyConfigured) as excinfo: - self.env('R4') - assert str(excinfo.value) == "Environment variable 'R4' recursively references itself (eventually)" diff --git a/tests/test_expansion.txt b/tests/test_expansion.txt deleted file mode 100755 index 8290e45f..00000000 --- a/tests/test_expansion.txt +++ /dev/null @@ -1,9 +0,0 @@ -VAR1='Hello' -VAR2='world' -HELLO="$VAR1, $VAR2!" -BRACES="${VAR1}, ${VAR2}!" -RECURSIVE="This variable is $RECURSIVE" -R1="$R2" -R2="$R3" -R3="$R4" -R4="$R1" From 55ff0e3fcd2872b56ac2e6aa613ba6381e4022ea Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 1 Sep 2023 12:20:12 +0200 Subject: [PATCH 03/40] Update change log --- CHANGELOG.rst | 4 ++-- environ/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a3a7806a..57cd6733 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. -`v0.12.0`_ - 00-Unreleased-2023 +`v0.12.0`_ - 1-September-2023 ------------------------------- Fixed +++++ @@ -388,7 +388,7 @@ Added - Initial release. -.. _v0.12.0: https://github.com/joke2k/django-environ/compare/v0.11.1...develop +.. _v0.12.0: https://github.com/joke2k/django-environ/compare/v0.11.1...v0.12.0 .. _v0.11.1: https://github.com/joke2k/django-environ/compare/v0.11.0...v0.11.1 .. _v0.11.0: https://github.com/joke2k/django-environ/compare/v0.10.0...v0.11.0 .. _v0.10.0: https://github.com/joke2k/django-environ/compare/v0.9.0...v0.10.0 diff --git a/environ/__init__.py b/environ/__init__.py index e7abf230..d469ecb7 100644 --- a/environ/__init__.py +++ b/environ/__init__.py @@ -18,7 +18,7 @@ from .environ import * -__copyright__ = 'Copyright (C) 2013-2022 Daniele Faraglia' +__copyright__ = 'Copyright (C) 2013-2023 Daniele Faraglia' """The copyright notice of the package.""" __version__ = '0.12.0' From 5561b352a9aebef89fe7d7bfc0d4d2bacd617813 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 1 Sep 2023 17:52:49 +0200 Subject: [PATCH 04/40] Change version: v0.12.0 -> v0.11.2 --- CHANGELOG.rst | 4 ++-- environ/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 57cd6733..cdb115f9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. -`v0.12.0`_ - 1-September-2023 +`v0.12.2`_ - 1-September-2023 ------------------------------- Fixed +++++ @@ -388,7 +388,7 @@ Added - Initial release. -.. _v0.12.0: https://github.com/joke2k/django-environ/compare/v0.11.1...v0.12.0 +.. _v0.11.2: https://github.com/joke2k/django-environ/compare/v0.11.1...v0.11.2 .. _v0.11.1: https://github.com/joke2k/django-environ/compare/v0.11.0...v0.11.1 .. _v0.11.0: https://github.com/joke2k/django-environ/compare/v0.10.0...v0.11.0 .. _v0.10.0: https://github.com/joke2k/django-environ/compare/v0.9.0...v0.10.0 diff --git a/environ/__init__.py b/environ/__init__.py index d469ecb7..28d4a5aa 100644 --- a/environ/__init__.py +++ b/environ/__init__.py @@ -21,7 +21,7 @@ __copyright__ = 'Copyright (C) 2013-2023 Daniele Faraglia' """The copyright notice of the package.""" -__version__ = '0.12.0' +__version__ = '0.11.2' """The version of the package.""" __license__ = 'MIT' From 928a65428ccb4589f4fbc7b5fdbadbab97435e43 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 1 Sep 2023 17:53:57 +0200 Subject: [PATCH 05/40] Change version: v0.12.0 -> v0.11.2 --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index cdb115f9..57c4c8dd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. -`v0.12.2`_ - 1-September-2023 +`v0.11.2`_ - 1-September-2023 ------------------------------- Fixed +++++ From 7b5d7f933dc91fd43d744f06d2282860ee53aa38 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:43:30 +0000 Subject: [PATCH 06/40] Bump actions/checkout from 3.6.0 to 4.0.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.0.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.6.0...v4.0.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0779431c..a4f895c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 @@ -64,7 +64,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ecdb2fe..6d1e916d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 with: fetch-depth: 5 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 07dd2008..e3e96503 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index fc596beb..99225771 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e03e0d8b..5da63970 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,7 +26,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 From e3e7fc9551858d1a41ed21ff7e46245e4f97652c Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 8 Sep 2023 22:14:57 +0200 Subject: [PATCH 07/40] Make inline comments handling optional and disabled by default Disabled inline comments handling (that was introduced in #475) by default due to potential side effects. While the feature itself is useful, the project's philosophy dictates that it should not be enabled by default for all users. This also fix the issue described in the #499. --- .gitignore | 2 +- CHANGELOG.rst | 16 +++++++++-- LICENSE.txt | 2 +- docs/tips.rst | 65 +++++++++++++++++++++++++++++++++++++++++++++ environ/__init__.py | 2 +- environ/environ.py | 46 +++++++++++++++++++++++--------- tests/test_env.py | 58 +++++++++++++++++++++++++++++++++++++--- tests/test_env.txt | 4 --- 8 files changed, 169 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 58629014..0b4fa311 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2023, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 57c4c8dd..ef00d40a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,8 +5,19 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. +`v0.11.3`_ - 0-Undefined-2023 +----------------------------- +Changed ++++++++ +- Disabled inline comments handling by default due to potential side effects. + While the feature itself is useful, the project's philosophy dictates that + it should not be enabled by default for all users + `#499 `_. + + + `v0.11.2`_ - 1-September-2023 -------------------------------- +----------------------------- Fixed +++++ - Revert "Add variable expansion." feature @@ -31,7 +42,7 @@ Added `#463 `_. - Added variable expansion `#468 `_. -- Added capability to handle comments after #, after quoted values, +- Added capability to handle comments after ``#``, after quoted values, like ``KEY= 'part1 # part2' # comment`` `#475 `_. - Added support for ``interpolate`` parameter @@ -388,6 +399,7 @@ Added - Initial release. +.. _v0.11.3: https://github.com/joke2k/django-environ/compare/v0.11.2...v0.11.3 .. _v0.11.2: https://github.com/joke2k/django-environ/compare/v0.11.1...v0.11.2 .. _v0.11.1: https://github.com/joke2k/django-environ/compare/v0.11.0...v0.11.1 .. _v0.11.0: https://github.com/joke2k/django-environ/compare/v0.10.0...v0.11.0 diff --git a/LICENSE.txt b/LICENSE.txt index 0bd208d6..8737f752 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2021, Serghei Iakovlev +Copyright (c) 2021-2023, Serghei Iakovlev Copyright (c) 2013-2021, Daniele Faraglia Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/docs/tips.rst b/docs/tips.rst index 20b8c3e1..66538c40 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -2,6 +2,71 @@ Tips ==== +Handling Inline Comments in .env Files +====================================== + +``django-environ`` provides an optional feature to parse inline comments in ``.env`` +files. This is controlled by the ``parse_comments`` parameter in the ``read_env`` +method. + +Modes +----- + +- **Enabled (``parse_comments=True``)**: Inline comments starting with ``#`` will be ignored. +- **Disabled (``parse_comments=False``)**: The entire line, including comments, will be read as the value. +- **Default**: The behavior is the same as when ``parse_comments=False``. + +Side Effects +------------ + +While this feature can be useful for adding context to your ``.env`` files, +it can introduce unexpected behavior. For example, if your value includes +a ``#`` symbol, it will be truncated when ``parse_comments=True``. + +Why Disabled by Default? +------------------------ + +In line with the project's philosophy of being explicit and avoiding unexpected behavior, +this feature is disabled by default. If you understand the implications and find the feature +useful, you can enable it explicitly. + +Example +------- + +Here is an example demonstrating the different modes of handling inline comments. + +**.env file contents**: + +.. code-block:: shell + + # .env file contents + BOOL_TRUE_WITH_COMMENT=True # This is a comment + STR_WITH_HASH=foo#bar # This is also a comment + +**Python code**: + +.. code-block:: python + + import environ + + # Using parse_comments=True + env = environ.Env() + env.read_env(parse_comments=True) + print(env('BOOL_TRUE_WITH_COMMENT')) # Output: True + print(env('STR_WITH_HASH')) # Output: foo + + # Using parse_comments=False + env = environ.Env() + env.read_env(parse_comments=False) + print(env('BOOL_TRUE_WITH_COMMENT')) # Output: True # This is a comment + print(env('STR_WITH_HASH')) # Output: foo#bar # This is also a comment + + # Using default behavior + env = environ.Env() + env.read_env() + print(env('BOOL_TRUE_WITH_COMMENT')) # Output: True # This is a comment + print(env('STR_WITH_HASH')) # Output: foo#bar # This is also a comment + Docker-style file based variables ================================= diff --git a/environ/__init__.py b/environ/__init__.py index 28d4a5aa..ddf05f92 100644 --- a/environ/__init__.py +++ b/environ/__init__.py @@ -21,7 +21,7 @@ __copyright__ = 'Copyright (C) 2013-2023 Daniele Faraglia' """The copyright notice of the package.""" -__version__ = '0.11.2' +__version__ = '0.11.3' """The version of the package.""" __license__ = 'MIT' diff --git a/environ/environ.py b/environ/environ.py index f74884be..a3d64f2d 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2023, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view @@ -862,8 +862,8 @@ def search_url_config(cls, url, engine=None): return config @classmethod - def read_env(cls, env_file=None, overwrite=False, encoding='utf8', - **overrides): + def read_env(cls, env_file=None, overwrite=False, parse_comments=False, + encoding='utf8', **overrides): r"""Read a .env file into os.environ. If not given a path to a dotenv path, does filthy magic stack @@ -883,6 +883,8 @@ def read_env(cls, env_file=None, overwrite=False, encoding='utf8', the Django settings module from the Django project root. :param overwrite: ``overwrite=True`` will force an overwrite of existing environment variables. + :param parse_comments: Determines whether to recognize and ignore + inline comments in the .env file. Default is False. :param encoding: The encoding to use when reading the environment file. :param \**overrides: Any additional keyword arguments provided directly to read_env will be added to the environment. If the key matches an @@ -927,22 +929,40 @@ def _keep_escaped_format_characters(match): for line in content.splitlines(): m1 = re.match(r'\A(?:export )?([A-Za-z_0-9]+)=(.*)\Z', line) if m1: + + # Example: + # + # line: KEY_499=abc#def + # key: KEY_499 + # val: abc#def key, val = m1.group(1), m1.group(2) - # Look for value in quotes, ignore post-# comments - # (outside quotes) - m2 = re.match(r"\A\s*'(? Date: Fri, 27 Oct 2023 10:26:29 +0200 Subject: [PATCH 08/40] Add Python 3.12 to the test matrix --- .github/workflows/build.yml | 2 +- .github/workflows/ci.yml | 3 ++- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- CHANGELOG.rst | 2 +- setup.py | 1 + tox.ini | 1 + 7 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a4f895c4..dee1699e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install tox tox-gh-actions + pip install tox tox-gh-actions setuptools - name: Check MANIFEST.in for completeness run: tox -e manifest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d1e916d..06d48ed6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: - '3.9' - '3.10' - '3.11' + - '3.12' - 'pypy-3.7' os: [ ubuntu-latest, macos-latest, windows-latest ] @@ -78,7 +79,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install tox tox-gh-actions + python -m pip install tox tox-gh-actions setuptools - name: Setuptools self-test run: | diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 99225771..47560734 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install tox tox-gh-actions + pip install tox tox-gh-actions setuptools - name: Lint with tox run: tox -e lint diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5da63970..3952a8f0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -36,7 +36,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install tox tox-gh-actions + pip install tox tox-gh-actions setuptools - name: Check external links in the package documentation run: tox -e linkcheck diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ef00d40a..6051aa4a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,13 +9,13 @@ and this project adheres to `Semantic Versioning `_. - `v0.11.2`_ - 1-September-2023 ----------------------------- Fixed diff --git a/setup.py b/setup.py index 30525752..14f998e0 100644 --- a/setup.py +++ b/setup.py @@ -159,6 +159,7 @@ def get_version_string(): 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', diff --git a/tox.ini b/tox.ini index d2367374..5ba15755 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ python = 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 pypy-3.7: pypy [testenv] From de22b7e1f1332e2b32fb4e6423553b1a532f2e2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:27:24 +0000 Subject: [PATCH 09/40] Bump actions/checkout from 4.0.0 to 4.1.1 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.0.0 to 4.1.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.0.0...v4.1.1) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dee1699e..f414d36e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 @@ -64,7 +64,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06d48ed6..685dfce6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.1 with: fetch-depth: 5 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e3e96503..460c1e33 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 47560734..f26771c7 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3952a8f0..fb129628 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,7 +26,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 From 46c035eade62b004b5cdc2063944aa3751313cbf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:32:09 +0000 Subject: [PATCH 10/40] Bump actions/setup-python from 4.7.0 to 4.7.1 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.7.0 to 4.7.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.7.0...v4.7.1) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f414d36e..4e28fa5a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.0 + uses: actions/setup-python@v4.7.1 with: python-version: '3.10' @@ -67,7 +67,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.0 + uses: actions/setup-python@v4.7.1 with: python-version: '3.10' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 685dfce6..1fe3f1d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: fetch-depth: 5 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v4.7.0 + uses: actions/setup-python@v4.7.1 with: python-version: ${{ matrix.python }} diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index f26771c7..4daad7d5 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -28,7 +28,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.0 + uses: actions/setup-python@v4.7.1 with: python-version: '3.10' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index fb129628..efef795c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.0 + uses: actions/setup-python@v4.7.1 with: python-version: '3.10' From a1113e41f134d3a5b2b6f98c81539f07da2269a7 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 24 Oct 2023 22:54:48 +0100 Subject: [PATCH 11/40] Test on Django 5.0 --- README.rst | 2 +- setup.py | 1 + tox.ini | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 528d1df1..dbb572ba 100644 --- a/README.rst +++ b/README.rst @@ -127,7 +127,7 @@ the code on `GitHub `_, and the latest release on `PyPI `_. It’s rigorously tested on Python 3.6+, and officially supports -Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0, 4.1 and 4.2. +Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, and 5.0. If you'd like to contribute to ``django-environ`` you're most welcome! diff --git a/setup.py b/setup.py index 14f998e0..fd3cd811 100644 --- a/setup.py +++ b/setup.py @@ -145,6 +145,7 @@ def get_version_string(): 'Framework :: Django :: 4.0', 'Framework :: Django :: 4.1', 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.0', 'Operating System :: OS Independent', diff --git a/tox.ini b/tox.ini index 5ba15755..fa3da3df 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,7 @@ envlist = py{36,37,38,39,310,311}-django{111,22} py{36,37,38,39,310,311}-django{30,31,32} py{38,39,310,311}-django{40,41,42} + py{310,311}-django{50} pypy-django{111,22,30,31,32} [gh-actions] From 7e9e32a2ca44b295fcbba18495ef47783dff5e6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Dec 2023 17:30:30 +0000 Subject: [PATCH 12/40] Bump github/codeql-action from 2 to 3 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v2...v3) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 460c1e33..8d7b98f5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -49,12 +49,12 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 From bead9cc8b2a93a0f9fd13de9653c6738c5f75afa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:39:50 +0000 Subject: [PATCH 13/40] Bump actions/setup-python from 4.7.1 to 5.0.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.7.1 to 5.0.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.7.1...v5.0.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e28fa5a..f81af5e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.0.0 with: python-version: '3.10' @@ -67,7 +67,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.0.0 with: python-version: '3.10' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fe3f1d6..ffc80378 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: fetch-depth: 5 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.0.0 with: python-version: ${{ matrix.python }} diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 4daad7d5..1fec6d45 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -28,7 +28,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.0.0 with: python-version: '3.10' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index efef795c..1647bb13 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.0.0 with: python-version: '3.10' From be3d74637aaea757015e5f63aeffde9152eb38cf Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 11:54:31 +0200 Subject: [PATCH 14/40] Add support for Python 3.13 and drop support for 3.6-3.8 --- .github/workflows/ci.yml | 12 +----------- README.rst | 2 +- setup.py | 4 +--- tox.ini | 12 +++++------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffc80378..1391678e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,24 +47,14 @@ jobs: matrix: python: - - '3.8' - '3.9' - '3.10' - '3.11' - '3.12' + - '3.13' - 'pypy-3.7' os: [ ubuntu-latest, macos-latest, windows-latest ] - # These versions are no longer supported by Python team, and may - # eventually be dropped from GitHub Actions. The support of these - # versions by django-environ will continue for as long as possible, - # and may be discontinued at any time. - include: - - python: '3.6' - os: ubuntu-20.04 - - python: '3.7' - os: ubuntu-20.04 - steps: - name: Checkout code uses: actions/checkout@v4.1.1 diff --git a/README.rst b/README.rst index dbb572ba..90cb46ff 100644 --- a/README.rst +++ b/README.rst @@ -126,7 +126,7 @@ its documentation lives at `Read the Docs `_, and the latest release on `PyPI `_. -It’s rigorously tested on Python 3.6+, and officially supports +It’s rigorously tested on Python 3.9+, and officially supports Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, and 5.0. If you'd like to contribute to ``django-environ`` you're most welcome! diff --git a/setup.py b/setup.py index fd3cd811..cfc68be4 100644 --- a/setup.py +++ b/setup.py @@ -154,13 +154,11 @@ def get_version_string(): 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', diff --git a/tox.ini b/tox.ini index fa3da3df..3703e049 100644 --- a/tox.ini +++ b/tox.ini @@ -18,21 +18,19 @@ envlist = docs lint manifest - py{36,37,38,39,310,311}-django{111,22} - py{36,37,38,39,310,311}-django{30,31,32} - py{38,39,310,311}-django{40,41,42} - py{310,311}-django{50} + py{39,310,311,312,313}-django{111,22} + py{39,310,311,312,313}-django{30,31,32} + py{39,310,311,312,313}-django{40,41,42} + py{310,311,312,313}-django{50} pypy-django{111,22,30,31,32} [gh-actions] python = - 3.6: py36 - 3.7: py37 - 3.8: py38 3.9: py39 3.10: py310 3.11: py311 3.12: py312 + 3.13: py313 pypy-3.7: pypy [testenv] From 3a611db2e35fc05530a19dfeef5cc195b94f125d Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 12:06:31 +0200 Subject: [PATCH 15/40] Bump pypy version to 3.10 --- .github/workflows/ci.yml | 4 ++-- tox.ini | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1391678e..dfd5cf45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ defaults: jobs: test: - name: Python ${{ matrix.python }} on ${{ matrix.os }} + name: CI ${{ matrix.python }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} # The maximum number of minutes to let a workflow run @@ -52,7 +52,7 @@ jobs: - '3.11' - '3.12' - '3.13' - - 'pypy-3.7' + - 'pypy-3.10' os: [ ubuntu-latest, macos-latest, windows-latest ] steps: diff --git a/tox.ini b/tox.ini index 3703e049..500c6016 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2023, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view @@ -31,7 +31,7 @@ python = 3.11: py311 3.12: py312 3.13: py313 - pypy-3.7: pypy + pypy-3.10: pypy [testenv] description = Unit tests From 3af3921badafc3fd03addfd1bed06488417c2dde Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 12:41:42 +0200 Subject: [PATCH 16/40] Add setuptools to dependency list for testing purposes --- .github/workflows/ci.yml | 2 +- setup.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dfd5cf45..32b597d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ defaults: jobs: test: - name: CI ${{ matrix.python }} on ${{ matrix.os }} + name: Python ${{ matrix.python }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} # The maximum number of minutes to let a workflow run diff --git a/setup.py b/setup.py index cfc68be4..802ba2bc 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ # # This file is part of the django-environ. # -# Copyright (c) 2021-2023, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view @@ -183,6 +183,7 @@ def get_version_string(): 'testing': [ 'coverage[toml]>=5.0a4', # Code coverage measurement for Python 'pytest>=4.6.11', # Our tests framework + 'setuptools>=71.0.0', # Needed as a dependency for some tests ], # Dependencies that are required to build documentation 'docs': [ From 3a58838109b55b6deac66ca47c89250c8c818e3a Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 13:08:01 +0200 Subject: [PATCH 17/40] Drop Django 1.x support --- README.rst | 2 +- setup.py | 3 --- tox.ini | 6 ++---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 90cb46ff..a4e6eefd 100644 --- a/README.rst +++ b/README.rst @@ -127,7 +127,7 @@ the code on `GitHub `_, and the latest release on `PyPI `_. It’s rigorously tested on Python 3.9+, and officially supports -Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, and 5.0. +Django 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, and 5.0. If you'd like to contribute to ``django-environ`` you're most welcome! diff --git a/setup.py b/setup.py index 802ba2bc..d7487be6 100644 --- a/setup.py +++ b/setup.py @@ -135,9 +135,6 @@ def get_version_string(): 'Development Status :: 5 - Production/Stable', 'Framework :: Django', - 'Framework :: Django :: 1.11', - 'Framework :: Django :: 2.0', - 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', 'Framework :: Django :: 3.0', 'Framework :: Django :: 3.1', diff --git a/tox.ini b/tox.ini index 500c6016..60d40fb4 100644 --- a/tox.ini +++ b/tox.ini @@ -18,11 +18,9 @@ envlist = docs lint manifest - py{39,310,311,312,313}-django{111,22} - py{39,310,311,312,313}-django{30,31,32} - py{39,310,311,312,313}-django{40,41,42} + py{39,310,311,312,313}-django{22,30,31,32,40,41,42} py{310,311,312,313}-django{50} - pypy-django{111,22,30,31,32} + pypy-django{22,30,31,32} [gh-actions] python = From ac6c0d46592ec2319b81db8657c7182d94c2e46a Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 14:55:14 +0200 Subject: [PATCH 18/40] Bump sphinx and furo --- setup.py | 4 ++-- tox.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index d7487be6..e74faeec 100644 --- a/setup.py +++ b/setup.py @@ -184,8 +184,8 @@ def get_version_string(): ], # Dependencies that are required to build documentation 'docs': [ - 'furo>=2021.8.17b43,==2021.8.*', # Sphinx documentation theme - 'sphinx>=3.5.0', # Python documentation generator + 'furo>=2024.8.6', # Sphinx documentation theme + 'sphinx>=5.0', # Python documentation generator 'sphinx-notfound-page', # Create a custom 404 page ], } diff --git a/tox.ini b/tox.ini index 60d40fb4..99f3c088 100644 --- a/tox.ini +++ b/tox.ini @@ -107,7 +107,7 @@ isolated_build = true description = Build package documentation (HTML) # Keep basepython in sync with .readthedocs.yml and docs.yml # (GitHub Action Workflow). -basepython = python3.10 +basepython = python3.13 extras = docs commands = {envpython} -m sphinx \ From 839b1f3c55d50cc80a26cd200df53fd55fff929f Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 15:09:16 +0200 Subject: [PATCH 19/40] Correct link to Two Scoops of Django --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a4e6eefd..58ceb9e6 100644 --- a/README.rst +++ b/README.rst @@ -97,7 +97,8 @@ approach, some connection strings are expressed as url, so this package can pars it and return a ``urllib.parse.ParseResult``. These strings from ``os.environ`` are loaded from a ``.env`` file and filled in ``os.environ`` with ``setdefault`` method, to avoid to overwrite the real environ. -A similar approach is used in `Two Scoops of Django `_ +A similar approach is used in +`Two Scoops of Django `_ book and explained in `12factor-django `_ article. From 01cd8e0ba56a5fab075e472cc72928ed97786144 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 15:11:55 +0200 Subject: [PATCH 20/40] Correct python version to test docs --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 99f3c088..60d40fb4 100644 --- a/tox.ini +++ b/tox.ini @@ -107,7 +107,7 @@ isolated_build = true description = Build package documentation (HTML) # Keep basepython in sync with .readthedocs.yml and docs.yml # (GitHub Action Workflow). -basepython = python3.13 +basepython = python3.10 extras = docs commands = {envpython} -m sphinx \ From 6321605a0562ad4d904cdd2c82722f5a5fc5fffe Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 15:17:36 +0200 Subject: [PATCH 21/40] Bump python version to test docs --- .github/workflows/docs.yml | 4 ++-- .readthedocs.yml | 4 ++-- tox.ini | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1647bb13..5726f5bf 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,10 +28,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.1 - - name: Set up Python 3.10 + - name: Set up Python 3.12 uses: actions/setup-python@v5.0.0 with: - python-version: '3.10' + python-version: '3.12' - name: Install dependencies run: | diff --git a/.readthedocs.yml b/.readthedocs.yml index 27f93688..191e9990 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view @@ -17,7 +17,7 @@ build: tools: # Keep version in sync with tox.ini (testenv:docs) and # docs.yml (GitHub Action Workflow). - python: '3.10' + python: '3.12' python: install: diff --git a/tox.ini b/tox.ini index 60d40fb4..f10624e3 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,6 @@ python = description = Unit tests extras = testing deps = - django111: Django>=1.11,<2 django22: Django>=2.2,<3.0 django30: Django>=3.0,<3.1 django31: Django>=3.1,<3.2 @@ -89,7 +88,7 @@ commands = description = Check external links in the package documentation # Keep basepython in sync with .readthedocs.yml and docs.yml # (GitHub Action Workflow). -basepython = python3.10 +basepython = python3.12 extras = docs commands = {envpython} -m sphinx \ @@ -107,7 +106,7 @@ isolated_build = true description = Build package documentation (HTML) # Keep basepython in sync with .readthedocs.yml and docs.yml # (GitHub Action Workflow). -basepython = python3.10 +basepython = python3.12 extras = docs commands = {envpython} -m sphinx \ From 04642ad37a4cc64cf811608a96155c2616594443 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 15:18:24 +0200 Subject: [PATCH 22/40] Bump python version to build and lint --- .github/workflows/build.yml | 8 ++++---- .github/workflows/cs.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f81af5e8..cc3cb14c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,10 +26,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.1 - - name: Set up Python 3.10 + - name: Set up Python 3.12 uses: actions/setup-python@v5.0.0 with: - python-version: '3.10' + python-version: '3.12' - name: Install dependencies run: | @@ -66,10 +66,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.1 - - name: Set up Python 3.10 + - name: Set up Python 3.12 uses: actions/setup-python@v5.0.0 with: - python-version: '3.10' + python-version: '3.12' - name: Install in dev mode run: python -m pip install -e . diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 1fec6d45..edd720d9 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -27,10 +27,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.1 - - name: Set up Python 3.10 + - name: Set up Python 3.12 uses: actions/setup-python@v5.0.0 with: - python-version: '3.10' + python-version: '3.12' - name: Install dependencies run: | From 7af0b84f622ef03b200e769f17b2139ee3699d67 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 15:33:08 +0200 Subject: [PATCH 23/40] Update documentation and change log --- CHANGELOG.rst | 15 ++++++++++++--- docs/install.rst | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6051aa4a..144659b8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,16 +5,25 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. -`v0.11.3`_ - 0-Undefined-2023 +`v0.12.0`_ - 0-Undefined-2024 ----------------------------- +Added ++++++ +- Add support for Python 3.12 and 3.13 + `#538 `_. + Changed +++++++ -- Formally support Python 3.12. - Disabled inline comments handling by default due to potential side effects. While the feature itself is useful, the project's philosophy dictates that it should not be enabled by default for all users `#499 `_. +Removed ++++++++ +- Removed support of Python 3.6, 3.7 and 3.8. +- Removed support of Django 1.x. + `v0.11.2`_ - 1-September-2023 ----------------------------- @@ -417,4 +426,4 @@ Added .. _v0.4.1: https://github.com/joke2k/django-environ/compare/v0.4...v0.4.1 .. _v0.4: https://github.com/joke2k/django-environ/compare/v0.3.1...v0.4 .. _v0.3.1: https://github.com/joke2k/django-environ/compare/v0.3...v0.3.1 -.. _v0.3: https://github.com/joke2k/django-environ/compare/v0.2.1...v0.3 \ No newline at end of file +.. _v0.3: https://github.com/joke2k/django-environ/compare/v0.2.1...v0.3 diff --git a/docs/install.rst b/docs/install.rst index 3dacca9e..b1a73c18 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -6,8 +6,8 @@ Installation Requirements ============ -* `Django `_ >= 1.11 -* `Python `_ >= 3.5 +* `Django `_ >= 2.2 +* `Python `_ >= 3.9 Installing django-environ ========================= From 09ef21ad37f60314d7d150d0de74ab1407cda141 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 15:44:57 +0200 Subject: [PATCH 24/40] Add support for Django 5.1 --- CHANGELOG.rst | 4 +++- README.rst | 2 +- setup.py | 3 ++- tox.ini | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 144659b8..8de3f0e6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,8 @@ Added +++++ - Add support for Python 3.12 and 3.13 `#538 `_. +- Add support for Django 5.1 + `#535 `_. Changed +++++++ @@ -408,7 +410,7 @@ Added - Initial release. -.. _v0.11.3: https://github.com/joke2k/django-environ/compare/v0.11.2...v0.11.3 +.. _v0.12.0: https://github.com/joke2k/django-environ/compare/v0.11.2...v0.12.0 .. _v0.11.2: https://github.com/joke2k/django-environ/compare/v0.11.1...v0.11.2 .. _v0.11.1: https://github.com/joke2k/django-environ/compare/v0.11.0...v0.11.1 .. _v0.11.0: https://github.com/joke2k/django-environ/compare/v0.10.0...v0.11.0 diff --git a/README.rst b/README.rst index 58ceb9e6..ff8e0125 100644 --- a/README.rst +++ b/README.rst @@ -128,7 +128,7 @@ the code on `GitHub `_, and the latest release on `PyPI `_. It’s rigorously tested on Python 3.9+, and officially supports -Django 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, and 5.0. +Django 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, and 5.1. If you'd like to contribute to ``django-environ`` you're most welcome! diff --git a/setup.py b/setup.py index e74faeec..e9272177 100644 --- a/setup.py +++ b/setup.py @@ -143,6 +143,7 @@ def get_version_string(): 'Framework :: Django :: 4.1', 'Framework :: Django :: 4.2', 'Framework :: Django :: 5.0', + 'Framework :: Django :: 5.1', 'Operating System :: OS Independent', @@ -228,7 +229,7 @@ def get_version_string(): platforms=['any'], include_package_data=True, zip_safe=False, - python_requires='>=3.6,<4', + python_requires='>=3.9,<4', install_requires=INSTALL_REQUIRES, dependency_links=DEPENDENCY_LINKS, extras_require=EXTRAS_REQUIRE, diff --git a/tox.ini b/tox.ini index f10624e3..a0b8dc28 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ envlist = lint manifest py{39,310,311,312,313}-django{22,30,31,32,40,41,42} - py{310,311,312,313}-django{50} + py{310,311,312,313}-django{50,51} pypy-django{22,30,31,32} [gh-actions] From 0ee91417b37b8a2660bf7f621b6092495ab88417 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:56:36 +0000 Subject: [PATCH 25/40] Bump actions/upload-artifact from 3 to 4 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- .github/workflows/docs.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc3cb14c..b5e76c06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: - name: Archive build artifacts if: success() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: # To ensure that jobs don't overwrite existing artifacts, # use a different name per job. diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5726f5bf..bbb560d3 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -46,7 +46,7 @@ jobs: - name: Archive docs artifacts if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: docs path: docs From 89686600c18d699f81f1d9dcfed9d394cdc48ba6 Mon Sep 17 00:00:00 2001 From: Spenser Black Date: Mon, 26 Feb 2024 16:05:38 -0500 Subject: [PATCH 26/40] Include prefix in the `ImproperlyConfigured` error --- environ/environ.py | 2 +- tests/test_env.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/environ/environ.py b/environ/environ.py index a3d64f2d..32a1b7ad 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -388,7 +388,7 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False): value = self.ENVIRON[var_name] except KeyError as exc: if default is self.NOTSET: - error_msg = f'Set the {var} environment variable' + error_msg = f'Set the {var_name} environment variable' raise ImproperlyConfigured(error_msg) from exc value = default diff --git a/tests/test_env.py b/tests/test_env.py index 85e0499f..ac383773 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -407,6 +407,13 @@ def test_prefix(self): self.env.prefix = 'PREFIX_' assert self.env('TEST') == 'foo' + def test_prefix_and_not_present_without_default(self): + self.env.prefix = 'PREFIX_' + with pytest.raises(ImproperlyConfigured) as excinfo: + self.env('not_present') + assert str(excinfo.value) == 'Set the PREFIX_not_present environment variable' + assert excinfo.value.__cause__ is not None + class TestFileEnv(TestEnv): def setup_method(self, method): From 023491a275d7335424729997e011f2b8b70614fc Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 25 Oct 2024 17:46:26 +0200 Subject: [PATCH 27/40] Bump version --- CHANGELOG.rst | 9 ++++++++- environ/__init__.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8de3f0e6..a4403a12 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,11 @@ and this project adheres to `Semantic Versioning `_. + Added +++++ - Add support for Python 3.12 and 3.13 @@ -23,8 +28,10 @@ Changed Removed +++++++ -- Removed support of Python 3.6, 3.7 and 3.8. +- Removed support of Python 3.6, 3.7 and 3.8 + `#538 `_. - Removed support of Django 1.x. + `#538 `_. `v0.11.2`_ - 1-September-2023 diff --git a/environ/__init__.py b/environ/__init__.py index ddf05f92..c590d713 100644 --- a/environ/__init__.py +++ b/environ/__init__.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2023, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view @@ -21,7 +21,7 @@ __copyright__ = 'Copyright (C) 2013-2023 Daniele Faraglia' """The copyright notice of the package.""" -__version__ = '0.11.3' +__version__ = '0.12.0' """The version of the package.""" __license__ = 'MIT' From 6c12976198c9a3c7034aa2f4400e490fb541a79b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:55:15 +0000 Subject: [PATCH 28/40] Bump actions/setup-python from 5.0.0 to 5.3.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.0.0 to 5.3.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v5.0.0...v5.3.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5e76c06..838abe37 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.12 - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.3.0 with: python-version: '3.12' @@ -67,7 +67,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.12 - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.3.0 with: python-version: '3.12' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32b597d2..db2a8eb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: fetch-depth: 5 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.3.0 with: python-version: ${{ matrix.python }} diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index edd720d9..77417978 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -28,7 +28,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.12 - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.3.0 with: python-version: '3.12' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bbb560d3..c6c832c1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.12 - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.3.0 with: python-version: '3.12' From 9fa66f2237f29ab0db3d99c4c1d74e6072d33682 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:55:18 +0000 Subject: [PATCH 29/40] Bump Vankka/pr-target-branch-action from 2 to 3 Bumps [Vankka/pr-target-branch-action](https://github.com/vankka/pr-target-branch-action) from 2 to 3. - [Release notes](https://github.com/vankka/pr-target-branch-action/releases) - [Commits](https://github.com/vankka/pr-target-branch-action/compare/v2...v3) --- updated-dependencies: - dependency-name: Vankka/pr-target-branch-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/change-pr-target.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/change-pr-target.yml b/.github/workflows/change-pr-target.yml index eb12a30c..af419d11 100644 --- a/.github/workflows/change-pr-target.yml +++ b/.github/workflows/change-pr-target.yml @@ -8,7 +8,7 @@ jobs: check-branch: runs-on: ubuntu-latest steps: - - uses: Vankka/pr-target-branch-action@v2 + - uses: Vankka/pr-target-branch-action@v3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From f53b3f499336dd7c583a2501614e7943c0615f06 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:03:34 +0000 Subject: [PATCH 30/40] Bump actions/checkout from 4.1.1 to 4.2.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.2.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.1.1...v4.2.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/cs.yml | 2 +- .github/workflows/docs.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 838abe37..342d5ce8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.2.2 - name: Set up Python 3.12 uses: actions/setup-python@v5.3.0 @@ -64,7 +64,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.2.2 - name: Set up Python 3.12 uses: actions/setup-python@v5.3.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db2a8eb7..0d80bfe7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.2.2 with: fetch-depth: 5 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8d7b98f5..d8236f32 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.2.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 77417978..30d41b99 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.2.2 - name: Set up Python 3.12 uses: actions/setup-python@v5.3.0 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c6c832c1..0ae19c36 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,7 +26,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.2.2 - name: Set up Python 3.12 uses: actions/setup-python@v5.3.0 From 6f0a91bcb49286556b5491c39e7d3f9cd228e022 Mon Sep 17 00:00:00 2001 From: Steve Williams Date: Sat, 25 Nov 2023 11:45:35 +0000 Subject: [PATCH 31/40] Add support for Django CockroachDB driver As per https://github.com/joke2k/django-environ/issues/509 adds support for Django CockroachDB --- environ/environ.py | 1 + tests/test_db.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/environ/environ.py b/environ/environ.py index 32a1b7ad..6595fc05 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -115,6 +115,7 @@ class Env: 'psql': DJANGO_POSTGRES, 'pgsql': DJANGO_POSTGRES, 'postgis': 'django.contrib.gis.db.backends.postgis', + 'cockroachdb': 'django_cockroachdb', 'mysql': 'django.db.backends.mysql', 'mysql2': 'django.db.backends.mysql', 'mysql-connector': 'mysql.connector.django', diff --git a/tests/test_db.py b/tests/test_db.py index 8101a4a7..a6995fd2 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -59,6 +59,14 @@ '', '' ), + # cockroachdb://username:secret@test.example.com:26258/dbname + ('cockroachdb://username:secret@test.example.com:26258/dbname', + 'django_cockroachdb', + 'dbname', + 'test.example.com', + 'username', + 'secret', + 26258), # mysqlgis://user:password@host:port/dbname ('mysqlgis://enigma:secret@example.com:5431/dbname', 'django.contrib.gis.db.backends.mysql', @@ -156,6 +164,7 @@ 'postgis', 'postgres_cluster', 'postgres_no_ports', + 'cockroachdb', 'mysqlgis', 'cleardb', 'mysql_no_password', From c8379ed2d1c1b4990aee5484a41e0c4697f1a95f Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 4 Nov 2024 09:08:40 +0100 Subject: [PATCH 32/40] Update copyright notice --- .gitignore | 2 +- LICENSE.txt | 2 +- MANIFEST.in | 2 +- SECURITY.rst | 2 +- docs/Makefile | 2 +- docs/conf.py | 2 +- docs/docutils.conf | 2 +- environ/__init__.py | 2 +- environ/compat.py | 2 +- environ/environ.py | 2 +- environ/fileaware_mapping.py | 2 +- tests/__init__.py | 2 +- tests/asserts.py | 2 +- tests/conftest.py | 2 +- tests/fixtures.py | 2 +- tests/test_cache.py | 2 +- tests/test_db.py | 2 +- tests/test_email.py | 2 +- tests/test_env.py | 2 +- tests/test_fileaware.py | 2 +- tests/test_path.py | 2 +- tests/test_schema.py | 2 +- tests/test_search.py | 2 +- tests/test_utils.py | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 0b4fa311..ec6473a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2023, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/LICENSE.txt b/LICENSE.txt index 8737f752..97cfd65e 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2021-2023, Serghei Iakovlev +Copyright (c) 2021-2024, Serghei Iakovlev Copyright (c) 2013-2021, Daniele Faraglia Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/MANIFEST.in b/MANIFEST.in index 9c2f064c..694e938d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/SECURITY.rst b/SECURITY.rst index 16ffdceb..f3ea149f 100644 --- a/SECURITY.rst +++ b/SECURITY.rst @@ -6,5 +6,5 @@ Reporting a Vulnerability ------------------------- If you discover a security vulnerability within ``django-environ``, please -send an e-mail to Serghei Iakovlev via egrep@protonmail.ch. All security +send an e-mail to Serghei Iakovlev via oss@serghei.pl. All security vulnerabilities will be promptly addressed. diff --git a/docs/Makefile b/docs/Makefile index 887c0bba..343425b6 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/docs/conf.py b/docs/conf.py index 8beac1f4..0e91d43c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2023, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/docs/docutils.conf b/docs/docutils.conf index 4ed0bf5a..d624b452 100644 --- a/docs/docutils.conf +++ b/docs/docutils.conf @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/environ/__init__.py b/environ/__init__.py index c590d713..8d29d2f1 100644 --- a/environ/__init__.py +++ b/environ/__init__.py @@ -36,7 +36,7 @@ __maintainer__ = 'Serghei Iakovlev' """The maintainer of the package.""" -__maintainer_email__ = 'egrep@protonmail.ch' +__maintainer_email__ = 'oss@serghei.pl' """The email of the maintainer of the package.""" __url__ = 'https://django-environ.readthedocs.org' diff --git a/environ/compat.py b/environ/compat.py index 49b5b480..55953fe5 100644 --- a/environ/compat.py +++ b/environ/compat.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/environ/environ.py b/environ/environ.py index 6595fc05..881379e5 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2023, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/environ/fileaware_mapping.py b/environ/fileaware_mapping.py index 0578945b..9d59e0ac 100644 --- a/environ/fileaware_mapping.py +++ b/environ/fileaware_mapping.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/__init__.py b/tests/__init__.py index 19f3cf24..c5fd8236 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/asserts.py b/tests/asserts.py index 3389e526..00d94b28 100644 --- a/tests/asserts.py +++ b/tests/asserts.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/conftest.py b/tests/conftest.py index 38550f73..ffdbf292 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/fixtures.py b/tests/fixtures.py index 69e5e90f..dc9fbd42 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_cache.py b/tests/test_cache.py index a8aff161..58e57e0b 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_db.py b/tests/test_db.py index a6995fd2..f1550643 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_email.py b/tests/test_email.py index 30d38139..c59ad83d 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_env.py b/tests/test_env.py index ac383773..5f0f4c9b 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_fileaware.py b/tests/test_fileaware.py index f411b7de..00442ae6 100644 --- a/tests/test_fileaware.py +++ b/tests/test_fileaware.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_path.py b/tests/test_path.py index b97f4caf..5d868d4d 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_schema.py b/tests/test_schema.py index 7a7f62ec..45f0e983 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_search.py b/tests/test_search.py index a6d8f061..81309213 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view diff --git a/tests/test_utils.py b/tests/test_utils.py index 2f3d32ee..02007179 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021-2022, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view From 0f2e088d27ac80b719d9e6b0fc6fc05182310d8c Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 4 Nov 2024 09:17:29 +0100 Subject: [PATCH 33/40] Update change log --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a4403a12..349588bf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,8 @@ Added `#538 `_. - Add support for Django 5.1 `#535 `_. +- Add support for Django CockroachDB driver + `#509 `_. Changed +++++++ From 872916551c49c6d870eb3fd1dfddaaf2db3c56a4 Mon Sep 17 00:00:00 2001 From: Yuchan Lee Date: Mon, 4 Dec 2023 13:35:16 +0000 Subject: [PATCH 34/40] feat: Channels URL support --- environ/environ.py | 45 ++++++++++++++++++++++++++++++++++++++++++ tests/test_channels.py | 20 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/test_channels.py diff --git a/environ/environ.py b/environ/environ.py index 881379e5..ad10de3c 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -190,6 +190,12 @@ class Env: for s in ('', 's')] CLOUDSQL = 'cloudsql' + DEFAULT_CHANNELS_ENV = "CHANNELS_URL" + CHANNELS_SCHEMES = { + "inmemory": "channels.layers.InMemoryChannelLayer", + "redis": "channels_redis.core.RedisChannelLayer" + } + def __init__(self, **scheme): self.smart_cast = True self.escape_proxy = False @@ -338,6 +344,18 @@ def search_url(self, var=DEFAULT_SEARCH_ENV, default=NOTSET, engine=None): engine=engine ) + def channels_url(self, var=DEFAULT_CHANNELS_ENV, default=NOTSET, backend=None): + """Returns a config dictionary, defaulting to CHANNELS_URL. + + :rtype: dict + """ + return self.channels_url_config( + self.url(var, default=default), + backend=backend + ) + + channels = channels_url + def path(self, var, default=NOTSET, **kwargs): """ :rtype: Path @@ -736,6 +754,33 @@ def email_url_config(cls, url, backend=None): config['OPTIONS'] = config_options return config + + @classmethod + def channels_url_config(cls, url, backend=None): + """Parse an arbitrary channels URL. + + :param urllib.parse.ParseResult or str url: + Email URL to parse. + :param str or None backend: + If None, the backend is evaluates from the ``url``. + :return: Parsed channels URL. + :rtype: dict + """ + config = {} + url = urlparse(url) if not isinstance(url, cls.URL_CLASS) else url + + if backend: + config["BACKEND"] = backend + elif url.scheme not in cls.CHANNELS_SCHEMES: + raise ImproperlyConfigured(f"Invalid channels schema {url.scheme}") + else: + config["BACKEND"] = cls.CHANNELS_SCHEMES[url.scheme] + if url.scheme == "redis": + config["CONFIG"] = { + "hosts": [url.geturl()] + } + + return config @classmethod def _parse_common_search_params(cls, url): diff --git a/tests/test_channels.py b/tests/test_channels.py new file mode 100644 index 00000000..821370f1 --- /dev/null +++ b/tests/test_channels.py @@ -0,0 +1,20 @@ +# This file is part of the django-environ. +# +# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2013-2021, Daniele Faraglia +# +# For the full copyright and license information, please view +# the LICENSE.txt file that was distributed with this source code. + +from environ import Env + + +def test_channels_parsing(): + url = "inmemory://" + result = Env.channels_url_config(url) + assert result["BACKEND"] == "channels.layers.InMemoryChannelLayer" + + url = "redis://user:password@localhost:5173/0" + result = Env.channels_url_config(url) + assert result["BACKEND"] == "channels_redis.core.RedisChannelLayer" + assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:5173/0" From 8b70d9f14fac9e9600f93869a45551a0eaa1e30d Mon Sep 17 00:00:00 2001 From: Yuchan Lee Date: Fri, 15 Dec 2023 15:35:22 +0000 Subject: [PATCH 35/40] feat: Redis Pub/Sub --- environ/environ.py | 7 ++++--- tests/test_channels.py | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/environ/environ.py b/environ/environ.py index ad10de3c..d83157a0 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -193,7 +193,8 @@ class Env: DEFAULT_CHANNELS_ENV = "CHANNELS_URL" CHANNELS_SCHEMES = { "inmemory": "channels.layers.InMemoryChannelLayer", - "redis": "channels_redis.core.RedisChannelLayer" + "redis": "channels_redis.core.RedisChannelLayer", + "redis+pubsub": "channels_redis.pubsub.RedisPubSubChannelLayer" } def __init__(self, **scheme): @@ -775,9 +776,9 @@ def channels_url_config(cls, url, backend=None): raise ImproperlyConfigured(f"Invalid channels schema {url.scheme}") else: config["BACKEND"] = cls.CHANNELS_SCHEMES[url.scheme] - if url.scheme == "redis": + if url.scheme in ("redis", "redis+pubsub"): config["CONFIG"] = { - "hosts": [url.geturl()] + "hosts": [url._replace(scheme="redis").geturl()] } return config diff --git a/tests/test_channels.py b/tests/test_channels.py index 821370f1..bf0a0666 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -18,3 +18,8 @@ def test_channels_parsing(): result = Env.channels_url_config(url) assert result["BACKEND"] == "channels_redis.core.RedisChannelLayer" assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:5173/0" + + url = "redis+pubsub://user:password@localhost:5173/0" + result = Env.channels_url_config(url) + assert result["BACKEND"] == "channels_redis.pubsub.RedisPubSubChannelLayer" + assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:5173/0" From 60164fd9a699bb0dc5c7f6f2af1743e6c15685af Mon Sep 17 00:00:00 2001 From: Yuchan Lee Date: Fri, 15 Dec 2023 15:35:48 +0000 Subject: [PATCH 36/40] chore: Prefer Redis default port 6379 --- tests/test_channels.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_channels.py b/tests/test_channels.py index bf0a0666..4912b078 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -14,12 +14,12 @@ def test_channels_parsing(): result = Env.channels_url_config(url) assert result["BACKEND"] == "channels.layers.InMemoryChannelLayer" - url = "redis://user:password@localhost:5173/0" + url = "redis://user:password@localhost:6379/0" result = Env.channels_url_config(url) assert result["BACKEND"] == "channels_redis.core.RedisChannelLayer" - assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:5173/0" + assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:6379/0" - url = "redis+pubsub://user:password@localhost:5173/0" + url = "redis+pubsub://user:password@localhost:6379/0" result = Env.channels_url_config(url) assert result["BACKEND"] == "channels_redis.pubsub.RedisPubSubChannelLayer" - assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:5173/0" + assert result["CONFIG"]["hosts"][0] == "redis://user:password@localhost:6379/0" From d92e11b5d992df1e75b895949217d07e52892465 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 4 Nov 2024 09:40:05 +0100 Subject: [PATCH 37/40] Update change log --- CHANGELOG.rst | 2 ++ tests/test_channels.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 349588bf..033cae2e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,8 @@ Added `#535 `_. - Add support for Django CockroachDB driver `#509 `_. +- Add support for Django Channels + `#266 `_. Changed +++++++ diff --git a/tests/test_channels.py b/tests/test_channels.py index 4912b078..64485a6f 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -1,6 +1,6 @@ # This file is part of the django-environ. # -# Copyright (c) 2021, Serghei Iakovlev +# Copyright (c) 2021-2024, Serghei Iakovlev # Copyright (c) 2013-2021, Daniele Faraglia # # For the full copyright and license information, please view From 6abdb8649bbfb13aa5290009171daf5ab5cc8fff Mon Sep 17 00:00:00 2001 From: Florian Demmer Date: Tue, 30 Jan 2024 14:28:52 +0100 Subject: [PATCH 38/40] Add tests for kwarg overriding engine/backend from urls --- tests/test_db.py | 10 ++++++++++ tests/test_email.py | 10 ++++++++++ tests/test_search.py | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/tests/test_db.py b/tests/test_db.py index f1550643..e26c5357 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -197,6 +197,16 @@ def test_db_parsing(url, engine, name, host, user, passwd, port): assert config['OPTIONS'] == {'reconnect': 'true'} +def test_custom_db_engine(): + """Override ENGINE determined from schema.""" + env_url = 'postgres://enigma:secret@example.com:5431/dbname' + + engine = 'mypackage.backends.whatever' + url = Env.db_url_config(env_url, engine=engine) + + assert url['ENGINE'] == engine + + def test_postgres_complex_db_name_parsing(): """Make sure we can use complex postgres host.""" env_url = ( diff --git a/tests/test_email.py b/tests/test_email.py index c59ad83d..1c9a8754 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -22,3 +22,13 @@ def test_smtp_parsing(): assert url['EMAIL_PORT'] == 587 assert url['EMAIL_USE_TLS'] is True assert url['EMAIL_FILE_PATH'] == '' + + +def test_custom_email_backend(): + """Override EMAIL_BACKEND determined from schema.""" + url = 'smtps://user@domain.com:password@smtp.example.com:587' + + backend = 'mypackage.backends.whatever' + url = Env.email_url_config(url, backend=backend) + + assert url['EMAIL_BACKEND'] == backend diff --git a/tests/test_search.py b/tests/test_search.py index 81309213..38f11f73 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -86,6 +86,16 @@ def test_elasticsearch_parsing(url, engine, scheme): assert url["URL"].startswith(scheme + ":") +def test_custom_search_engine(): + """Override ENGINE determined from schema.""" + env_url = 'elasticsearch://127.0.0.1:9200/index' + + engine = 'mypackage.backends.whatever' + url = Env.db_url_config(env_url, engine=engine) + + assert url['ENGINE'] == engine + + @pytest.mark.parametrize('storage', ['file', 'ram']) def test_whoosh_parsing(whoosh_url, storage): post_limit = 128 * 1024 * 1024 From 8e844ac42ce215ba5fca36e38161fde44137b06a Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 4 Nov 2024 09:48:05 +0100 Subject: [PATCH 39/40] Correct code style --- environ/environ.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/environ/environ.py b/environ/environ.py index d83157a0..5536f2c7 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -191,7 +191,7 @@ class Env: CLOUDSQL = 'cloudsql' DEFAULT_CHANNELS_ENV = "CHANNELS_URL" - CHANNELS_SCHEMES = { + CHANNELS_SCHEMES = { "inmemory": "channels.layers.InMemoryChannelLayer", "redis": "channels_redis.core.RedisChannelLayer", "redis+pubsub": "channels_redis.pubsub.RedisPubSubChannelLayer" @@ -345,7 +345,8 @@ def search_url(self, var=DEFAULT_SEARCH_ENV, default=NOTSET, engine=None): engine=engine ) - def channels_url(self, var=DEFAULT_CHANNELS_ENV, default=NOTSET, backend=None): + def channels_url(self, var=DEFAULT_CHANNELS_ENV, default=NOTSET, + backend=None): """Returns a config dictionary, defaulting to CHANNELS_URL. :rtype: dict @@ -755,7 +756,7 @@ def email_url_config(cls, url, backend=None): config['OPTIONS'] = config_options return config - + @classmethod def channels_url_config(cls, url, backend=None): """Parse an arbitrary channels URL. @@ -769,7 +770,7 @@ def channels_url_config(cls, url, backend=None): """ config = {} url = urlparse(url) if not isinstance(url, cls.URL_CLASS) else url - + if backend: config["BACKEND"] = backend elif url.scheme not in cls.CHANNELS_SCHEMES: @@ -856,7 +857,7 @@ def search_url_config(cls, url, engine=None): :param urllib.parse.ParseResult or str url: Search URL to parse. :param str or None engine: - If None, the engine is evaluates from the ``url``. + If None, the engine is evaluating from the ``url``. :return: Parsed search URL. :rtype: dict """ From 00c8203a238c7908b30c97dccca71344566d9d0e Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 8 Nov 2024 19:51:07 +0100 Subject: [PATCH 40/40] Update change log --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 033cae2e..9ccc1824 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is inspired by `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. -`v0.12.0`_ - 0-Undefined-2024 +`v0.12.0`_ - 8-November-2024 ----------------------------- Fixed +++++