From a60bebb83288fa4fc7413fc5694b3ca29cc6d147 Mon Sep 17 00:00:00 2001 From: Gregory Tappero Date: Mon, 13 Dec 2021 04:47:11 +0100 Subject: [PATCH 1/6] bump Django dep to <=4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cd63b97..72fee18 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import find_packages, setup -install_requires = ["Django>=1.11,<3.3"] +install_requires = ["Django>=1.11,<=4"] testing_extras = [ "coverage>=3.7.0", From 0325fb47325b66adf195fd99aa9eb7d1b247e26d Mon Sep 17 00:00:00 2001 From: Gregory Tappero Date: Tue, 14 Dec 2021 05:57:53 +1100 Subject: [PATCH 2/6] update tox.ini and README with Django 4 --- .github/workflows/test.yml | 7 ++++++- README.md | 17 +++++++++-------- tox.ini | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b095c41..7f0a527 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,18 +34,23 @@ jobs: toxenv: - py36-dj22 - py36-dj32 + - py36-dj40 - py38-dj22 - py38-dj32 + - py38-dj40 include: - toxenv: py36-dj22 python-version: 3.6 - toxenv: py36-dj32 python-version: 3.6 + - toxenv: py36-dj40 + python-version: 3.6 - toxenv: py38-dj22 python-version: 3.8 - toxenv: py38-dj32 python-version: 3.8 - + - toxenv: py38-dj40 + python-version: 3.8 steps: - uses: actions/checkout@v1 diff --git a/README.md b/README.md index 87524ee..52ac0a4 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,19 @@ Feature flags allow you to toggle functionality in both Django code and the Django templates based on configurable conditions. Flags can be useful for staging feature deployments, for A/B testing, or for any time you need an on/off switch for blocks of code. The toggle can be by date, user, URL value, or a number of [other conditions](https://cfpb.github.io/django-flags/conditions/), editable in the admin or in definable in settings. -- [Dependencies](#dependencies) -- [Installation](#installation) -- [Documentation](#documentation) -- [Getting help](#getting-help) -- [Getting involved](#getting-involved) -- [Licensing](#licensing) -- [Credits and references](#credits-and-references) +- [Django-Flags](#django-flags) + - [Dependencies](#dependencies) + - [Installation](#installation) + - [Documentation](#documentation) + - [Getting help](#getting-help) + - [Getting involved](#getting-involved) + - [Licensing](#licensing) + - [Credits and references](#credits-and-references) ## Dependencies - Python 3.6+ -- Django 2.2-3.2 +- Django 2.2-4 ## Installation diff --git a/tox.ini b/tox.ini index cef34b7..fe783f5 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ basepython= deps= dj22: Django>=2.2,<2.3 dj32: Django>=3.2,<3.3 + dj40: Django==4 [testenv:lint] basepython=python3.8 From 4e1ad90b5289e67269dcf5b8054ec9d089861413 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Mon, 10 Jan 2022 10:47:12 -0500 Subject: [PATCH 3/6] Update Django Debug Toolbar version range --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 72fee18..e9f9749 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ testing_extras = [ "coverage>=3.7.0", - "django-debug-toolbar>=2.0,<2.3", + "django-debug-toolbar>=3.2,<4", "jinja2", ] From 43386e50248a60abf5b83b4e3370def8211c105f Mon Sep 17 00:00:00 2001 From: Will Barton Date: Mon, 10 Jan 2022 10:48:02 -0500 Subject: [PATCH 4/6] Update to Python 3.9 and only test Django 4.0 with 3.9 --- .github/workflows/test.yml | 25 ++++++++++------------- flags/state.py | 3 ++- flags/tests/test_conditions_validators.py | 10 +++++++-- tox.ini | 10 ++++----- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f0a527..2e08b6c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,10 +19,10 @@ jobs: run: | python -m pip install --upgrade pip pip install tox - + - name: Run tox -e lint run: tox - env: + env: TOXENV: lint test: @@ -34,23 +34,20 @@ jobs: toxenv: - py36-dj22 - py36-dj32 - - py36-dj40 - - py38-dj22 - - py38-dj32 - - py38-dj40 + - py39-dj22 + - py39-dj32 + - py39-dj40 include: - toxenv: py36-dj22 python-version: 3.6 - toxenv: py36-dj32 python-version: 3.6 - - toxenv: py36-dj40 - python-version: 3.6 - - toxenv: py38-dj22 - python-version: 3.8 - - toxenv: py38-dj32 - python-version: 3.8 - - toxenv: py38-dj40 + - toxenv: py39-dj22 + python-version: 3.9 + - toxenv: py39-dj32 python-version: 3.8 + - toxenv: py39-dj40 + python-version: 3.9 steps: - uses: actions/checkout@v1 @@ -68,7 +65,7 @@ jobs: run: | tox coveralls - env: + env: TOXENV: ${{ matrix.toxenv }} COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/flags/state.py b/flags/state.py index a41428c..cfb75b9 100644 --- a/flags/state.py +++ b/flags/state.py @@ -1,7 +1,6 @@ from django.apps import apps from django.core.exceptions import AppRegistryNotReady -from flags.models import FlagState from flags.sources import get_flags @@ -20,6 +19,8 @@ def _set_flag_state( flag_name, state, create_boolean_condition=True, request=None ): """A private function to set a boolean condition to the desired state""" + from flags.models import FlagState + flags = get_flags(request=request) flag = flags.get(flag_name) if flag is None: diff --git a/flags/tests/test_conditions_validators.py b/flags/tests/test_conditions_validators.py index aaa3ec1..3e0db48 100644 --- a/flags/tests/test_conditions_validators.py +++ b/flags/tests/test_conditions_validators.py @@ -1,3 +1,4 @@ +import django from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.test import TestCase, override_settings @@ -87,8 +88,13 @@ class ValidateDateTestCase(TestCase): def test_invalid_date_strings(self): with self.assertRaises(ValidationError): validate_date("tomorrowish") - with self.assertRaises(ValidationError): - validate_date("2020-04-01") + + # Django 4.0 relies on Python 3.7+'s `datetime.fromisoformat()`, which + # handles this where the old regex did not. This is now valid when on + # Django 4.0+. See https://github.com/django/django/pull/14582 + if django.VERSION < (4, 0): + with self.assertRaises(ValidationError): + validate_date("2020-04-01") def test_valid_date_strings(self): validate_date("2020-04-01T12:00") diff --git a/tox.ini b/tox.ini index fe783f5..194367e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,27 +1,27 @@ [tox] skipsdist=True -envlist=lint,py{36,38}-dj{22,32} +envlist=lint,py{36,39}-dj{22,32},py39-dj40 [testenv] install_command=pip install -e ".[testing]" -U {opts} {packages} commands= coverage erase - coverage run --source='flags' {envbindir}/django-admin.py test {posargs} + coverage run --source='flags' {envbindir}/django-admin test {posargs} coverage report -m setenv= DJANGO_SETTINGS_MODULE=flags.tests.settings basepython= py36: python3.6 - py38: python3.8 + py39: python3.9 deps= dj22: Django>=2.2,<2.3 dj32: Django>=3.2,<3.3 - dj40: Django==4 + dj40: Django>=4.0,<4.1 [testenv:lint] -basepython=python3.8 +basepython=python3.9 deps= black flake8 From a1b9174016c77ba8eb03406dd6455c578b82d9a6 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Mon, 10 Jan 2022 10:52:31 -0500 Subject: [PATCH 5/6] Update the release notes in anticipation of release --- README.md | 19 +++++++++---------- docs/releasenotes.md | 11 +++++++++-- setup.py | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 52ac0a4..236ccf8 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,18 @@ Feature flags allow you to toggle functionality in both Django code and the Django templates based on configurable conditions. Flags can be useful for staging feature deployments, for A/B testing, or for any time you need an on/off switch for blocks of code. The toggle can be by date, user, URL value, or a number of [other conditions](https://cfpb.github.io/django-flags/conditions/), editable in the admin or in definable in settings. -- [Django-Flags](#django-flags) - - [Dependencies](#dependencies) - - [Installation](#installation) - - [Documentation](#documentation) - - [Getting help](#getting-help) - - [Getting involved](#getting-involved) - - [Licensing](#licensing) - - [Credits and references](#credits-and-references) +- [Dependencies](#dependencies) +- [Installation](#installation) +- [Documentation](#documentation) +- [Getting help](#getting-help) +- [Getting involved](#getting-involved) +- [Licensing](#licensing) +- [Credits and references](#credits-and-references) ## Dependencies - Python 3.6+ -- Django 2.2-4 +- Django 2.2-4.0 ## Installation @@ -40,7 +39,7 @@ pip install django-flags ## Documentation -https://cfpb.github.io/django-flags is the full documentation for Django-Flags, and includes how to get started, general usage, and an API reference. +https://cfpb.github.io/django-flags is the full documentation for Django-Flags, and includes how to get started, general usage, and an API reference. ## Getting help diff --git a/docs/releasenotes.md b/docs/releasenotes.md index 870eada..22e6ce9 100644 --- a/docs/releasenotes.md +++ b/docs/releasenotes.md @@ -1,5 +1,12 @@ # Release Notes +## 5.0.6 + +### What's new? + +- Added Django 4.0 support (thanks [@gregtap](https://github.com/gregtap)!) + + ## 5.0.5 ### What's new? @@ -131,7 +138,7 @@ ### What's new? - The template functions `flag_enabled` and `flag_disabled` in both [Django](/api/django) and [Jinja2](/api/jinja2) templates now support taking keyword arguments that could be used by [custom conditions](/api/conditions). -- Jinja2 template functions are now available via a Jinja2 extension that can be [included in `settings.py`](/api/jinja2). +- Jinja2 template functions are now available via a Jinja2 extension that can be [included in `settings.py`](/api/jinja2). - The optional `flags.middleware.FlagConditionsMiddleware` has been added to ensure that all feature flag checks throughout single request cycle use the same flag conditions. - Support for specifying the [source of feature flags in `settings.py`](/settings#flag_sources) has been added to allow further customization and the potential to limit flags to settings or database-only. - The "user" condition now supports custom user models. ([@callorico](https://github.com/callorico)) @@ -157,7 +164,7 @@ TEMPLATES = [ ], } }, -] +] ``` ## 3.0.2 diff --git a/setup.py b/setup.py index e9f9749..9d6afd3 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ long_description=open("README.md", "r", encoding="utf-8").read(), long_description_content_type="text/markdown", license="CC0", - version="5.0.5", + version="5.0.6", include_package_data=True, packages=find_packages(), python_requires=">=3.6", From 36143f2797e90aa83975d8ebaf1a562a964fb046 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Mon, 10 Jan 2022 10:55:36 -0500 Subject: [PATCH 6/6] Fix GitHub actions Python versions --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2e08b6c..5509eb7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | @@ -45,7 +45,7 @@ jobs: - toxenv: py39-dj22 python-version: 3.9 - toxenv: py39-dj32 - python-version: 3.8 + python-version: 3.9 - toxenv: py39-dj40 python-version: 3.9 steps: