From c22cef24641ecac711047abda303e775d9f125a9 Mon Sep 17 00:00:00 2001 From: Andy Zickler Date: Fri, 17 Dec 2021 22:51:37 -0500 Subject: [PATCH 1/2] Fix Django 3.2 and 4.0 deprecation warnings * Adds django 3.2 and 4.0 to tox * Setup tox to display all warnings * Fixes the following warnings: RemovedInDjango40Warning: django-admin.py is deprecated in favor of django-admin. tests/urls.py:11: RemovedInDjango40Warning: django.conf.urls.url() is deprecated in favor of django.urls.re_path(). url(r'^ajax_lookups/', include(ajax_select_urls)), tests.Author: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. RemovedInDjango41Warning: 'ajax_select' defines default_app_config = 'ajax_select.apps.AjaxSelectConfig'. Django now detects this configuration automatically. You can remove default_app_config. --- ajax_select/__init__.py | 7 ++++++- tests/settings.py | 2 ++ tests/urls.py | 6 +++--- tox.ini | 8 +++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ajax_select/__init__.py b/ajax_select/__init__.py index b520f3a216..6ff72652e1 100644 --- a/ajax_select/__init__.py +++ b/ajax_select/__init__.py @@ -13,4 +13,9 @@ # and any specified in settings.AJAX_LOOKUP_CHANNELS # It will do this after all apps are imported. from django.apps import AppConfig # noqa -default_app_config = 'ajax_select.apps.AjaxSelectConfig' + +# Django 3.2+ does not need default_app_config set. +# Remove this once django <3.2 support is removed +import django +if django.VERSION < (3, 2): + default_app_config = 'ajax_select.apps.AjaxSelectConfig' diff --git a/tests/settings.py b/tests/settings.py index fc3e5ad0f3..e7c4eae109 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -5,6 +5,8 @@ "ENGINE": "django.db.backends.sqlite3", } } +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + ROOT_URLCONF = "tests.urls" INSTALLED_APPS = [ "django.contrib.auth", diff --git a/tests/urls.py b/tests/urls.py index bb80a61635..d1bf0e2714 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.conf.urls import include, url +from django.urls import include, path from django.conf.urls.static import static from django.contrib import admin @@ -8,6 +8,6 @@ admin.autodiscover() urlpatterns = [ - url(r'^ajax_lookups/', include(ajax_select_urls)), - url(r'^admin/', admin.site.urls), + path('ajax_lookups/', include(ajax_select_urls)), + path('admin/', admin.site.urls), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/tox.ini b/tox.ini index 17296165ea..c10442f152 100644 --- a/tox.ini +++ b/tox.ini @@ -7,17 +7,19 @@ [tox] envlist = {py38}-flake8, - py38-{dj22,dj30,dj31} - + py38-{dj22,dj30,dj31,dj32,dj40} [testenv] setenv = DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH = {toxinidir}:{toxinidir}/ajax_select:{toxinidir}/tests -commands = django-admin.py test tests + PYTHONWARNINGS = default +commands = django-admin test tests deps = dj22: Django>=2.2,<2.3 dj30: Django>=3,<3.1 dj31: Django>=3.1,<3.2 + dj32: Django>=3.2,<3.3 + dj40: Django>=4,<4.1 ; djmaster: https://github.com/django/django/zipball/master [testenv:py38-flake8] From af4fc6130c0abab0d26af72bfbe49a257f889159 Mon Sep 17 00:00:00 2001 From: Andy Zickler Date: Fri, 7 Jan 2022 22:43:03 -0500 Subject: [PATCH 2/2] Add github workflow to run tox --- .github/workflows/tests.yml | 39 +++++++++++++++++++++++++++++++++++++ tox.ini | 9 ++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000000..dec5acf9d4 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,39 @@ +# This is a basic workflow to help you get started with Actions + +name: Tests + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the develop branch + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10'] + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + - name: Test with tox + run: tox diff --git a/tox.ini b/tox.ini index c10442f152..07a75da673 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,14 @@ [tox] envlist = {py38}-flake8, - py38-{dj22,dj30,dj31,dj32,dj40} + {py38,py39,py310}-{dj22,dj30,dj31,dj32,dj40} + +[gh-actions] +python = + 3.8: py38 + 3.9: py39 + 3.10: py310 + [testenv] setenv = DJANGO_SETTINGS_MODULE=tests.settings