From 933a69a7448411d042b12709954adc428b61e264 Mon Sep 17 00:00:00 2001 From: Tom Carrick Date: Sun, 20 Feb 2022 15:39:50 +0100 Subject: [PATCH] Modernise codebase (#14) - Updates linting configuration. - Updates CI workflow to cancel in progress CI runs when you push a new commit. - Swaps from feature checking to version checking for `JSONField`. --- .github/workflows/ci.yml | 11 ++++++----- requirements.txt | 3 +-- runtests.py | 1 - setup.cfg | 18 ++++++------------ setup.py | 1 - snakeoil/admin.py | 1 - snakeoil/migrations/0001_initial.py | 1 - snakeoil/migrations/0002_auto_20200727_0951.py | 1 - snakeoil/models.py | 14 ++++++-------- snakeoil/templatetags/snakeoil.py | 1 - snakeoil/utils.py | 1 - tests/migrations/0001_initial.py | 1 - tests/models.py | 1 - tests/settings.py | 1 - tests/test_models.py | 1 - tests/test_template_tags.py | 1 - tests/urls.py | 1 - 17 files changed, 19 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dbdb0f..755530f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,21 +10,22 @@ on: types: - published +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: black: runs-on: ubuntu-latest steps: - - uses: actions/setup-python@v2 - - uses: actions/checkout@v2 - - run: python -m pip install black - - run: black --check snakeoil tests + - uses: psf/black@stable flake8: runs-on: ubuntu-latest steps: - uses: actions/setup-python@v2 - uses: actions/checkout@v2 - - run: python -m pip install flake8 flake8-bugbear + - run: python -m pip install flake8 - run: flake8 isort: diff --git a/requirements.txt b/requirements.txt index c000ca8..ea76499 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,8 @@ # Development requirements. black coverage -django~=3.2 +django~=4.0 flake8 -flake8-bugbear isort pillow rstcheck diff --git a/runtests.py b/runtests.py index f5f7222..d11b695 100755 --- a/runtests.py +++ b/runtests.py @@ -6,7 +6,6 @@ import django from django.test.runner import DiscoverRunner - if __name__ == "__main__": os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings" django.setup() diff --git a/setup.cfg b/setup.cfg index d70f764..924c82b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,18 +6,11 @@ omit = setup.py [flake8] -ignore = B008, E501, W503 -max-line-length = 80 -select = B, B950, C, D, E, F, W +max-line-length = 88 +extend-ignore = E203 [isort] -force_grid_wrap = 0 -include_trailing_comma = true -line_length = 88 -lines_after_imports = 2 -multi_line_output = 3 -sections = FUTURE, STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER -use_parentheses = True +profile = black [metadata] author = Tom Carrick @@ -29,9 +22,10 @@ classifiers = License :: OSI Approved :: MIT License Operating System :: OS Independent Programming Language :: Python :: 3 :: Only - 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 Topic :: Internet :: WWW/HTTP :: Site Management description = Simple SEO & meta tag management for Django keywords = @@ -41,7 +35,7 @@ keywords = long_description = file: README.rst name = django-snakeoil url = https://github.com/knyghty/django-snakeoil -version = 1.1.1 +version = 1.1.2 [options] include_package_data = true diff --git a/setup.py b/setup.py index 2598061..c823345 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python from setuptools import setup - setup() diff --git a/snakeoil/admin.py b/snakeoil/admin.py index beed5f2..79600d7 100644 --- a/snakeoil/admin.py +++ b/snakeoil/admin.py @@ -2,5 +2,4 @@ from .models import SEOPath - admin.site.register(SEOPath) diff --git a/snakeoil/migrations/0001_initial.py b/snakeoil/migrations/0001_initial.py index 0a152a9..bcc99a8 100644 --- a/snakeoil/migrations/0001_initial.py +++ b/snakeoil/migrations/0001_initial.py @@ -1,6 +1,5 @@ from django.db import migrations, models - try: from django.db.models import JSONField diff --git a/snakeoil/migrations/0002_auto_20200727_0951.py b/snakeoil/migrations/0002_auto_20200727_0951.py index 4fb286f..c3a8b18 100644 --- a/snakeoil/migrations/0002_auto_20200727_0951.py +++ b/snakeoil/migrations/0002_auto_20200727_0951.py @@ -1,6 +1,5 @@ from django.db import migrations - try: from django.db.models import JSONField diff --git a/snakeoil/models.py b/snakeoil/models.py index 7b5909d..9b09e17 100644 --- a/snakeoil/models.py +++ b/snakeoil/models.py @@ -1,15 +1,13 @@ +import django from django.db import models from django.utils.translation import gettext_lazy as _ - -try: - from django.db.models import JSONField - - postgres_only = False -except ImportError: - from django.contrib.postgres.fields import JSONField - +if django.VERSION <= (3, 0): postgres_only = True + from django.contrib.postgres.fields import JSONField +else: + postgres_only = False + from django.db.models import JSONField class SEOModel(models.Model): diff --git a/snakeoil/templatetags/snakeoil.py b/snakeoil/templatetags/snakeoil.py index da08c51..6849564 100644 --- a/snakeoil/templatetags/snakeoil.py +++ b/snakeoil/templatetags/snakeoil.py @@ -2,7 +2,6 @@ from ..utils import get_meta_tags - register = template.Library() diff --git a/snakeoil/utils.py b/snakeoil/utils.py index a5eed04..a595955 100644 --- a/snakeoil/utils.py +++ b/snakeoil/utils.py @@ -9,7 +9,6 @@ from .models import SEOPath - logger = logging.getLogger(__name__) register = template.Library() diff --git a/tests/migrations/0001_initial.py b/tests/migrations/0001_initial.py index da40347..e52c82c 100644 --- a/tests/migrations/0001_initial.py +++ b/tests/migrations/0001_initial.py @@ -2,7 +2,6 @@ from django.conf import settings from django.db import migrations, models - try: from django.db.models import JSONField except ImportError: diff --git a/tests/models.py b/tests/models.py index b38f218..b1ed209 100644 --- a/tests/models.py +++ b/tests/models.py @@ -4,7 +4,6 @@ from snakeoil.models import SEOModel - User = get_user_model() diff --git a/tests/settings.py b/tests/settings.py index c977230..dc4c884 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,7 +1,6 @@ import os from pathlib import Path - TESTS_DIR = Path(__file__).resolve(strict=True).parents[0] db = os.getenv("DB") diff --git a/tests/test_models.py b/tests/test_models.py index 843d6c1..a126ba2 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -5,7 +5,6 @@ from .models import Article - User = get_user_model() diff --git a/tests/test_template_tags.py b/tests/test_template_tags.py index c48afcd..829b4a6 100644 --- a/tests/test_template_tags.py +++ b/tests/test_template_tags.py @@ -9,7 +9,6 @@ from .models import Article - User = get_user_model() diff --git a/tests/urls.py b/tests/urls.py index b20bf0e..ef1a13f 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -2,7 +2,6 @@ from . import views - urlpatterns = [ path( "articles//",