From 1fb6fca1eec03bec2fe97c2be330ec64c856605b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=82=85=E7=91=9E=E6=9B=BC?= Date: Thu, 14 Mar 2024 15:35:15 +0800 Subject: [PATCH] init support for django4.2 (#150) * init support for django4.2 * add change log for add compatiable for django 4.2 and python 3.10 * Update CHANGELOG.rst * Update .pre-commit-config.yaml * fix lint config issue * remove test code * add blackline for flake8 * add pyproject.toml file * add requirement files * fix ci failed issue * format setup.py import section * upgrade isort version to fix pre commit ci issue * upgrade the django-upgrade package to pass through the pre commit ci test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * upgrade packages in pre commit * resort init file changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comment the django-upgrade from ci * fix: add missing migration file * fix: update previous file instead of creating new file --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Josh Peng Yu --- .github/workflows/lint.yml | 4 +- .github/workflows/test.yml | 4 +- .pre-commit-config.yaml | 22 +-- CHANGELOG.rst | 4 + djangocms_snippet/admin.py | 14 +- djangocms_snippet/forms.py | 2 +- ...0005_set_related_name_for_cmsplugin_ptr.py | 2 +- djangocms_snippet/settings.py | 32 ++++ pyproject.toml | 141 ++++++++++++++++++ requirements.in | 6 + requirements.txt | 83 +++++++++++ setup.py | 15 +- tests/requirements/base.txt | 4 - tests/requirements/dj22_cms40.txt | 3 - tests/requirements/dj32_cms40.txt | 4 + tests/requirements/dj42_cms40.txt | 7 + tox.ini | 12 +- 17 files changed, 314 insertions(+), 45 deletions(-) create mode 100644 djangocms_snippet/settings.py create mode 100644 pyproject.toml create mode 100644 requirements.in create mode 100644 requirements.txt delete mode 100644 tests/requirements/dj22_cms40.txt create mode 100644 tests/requirements/dj42_cms40.txt diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 95283181..1d16b2e1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: '3.10' - name: Install flake8 run: pip install --upgrade flake8 - name: Run flake8 @@ -29,7 +29,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: '3.10' - run: python -m pip install isort - name: isort uses: liskin/gh-problem-matcher-wrap@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5804387b..a9b84fd2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,10 +8,10 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.7, 3.8, 3.9 ] + python-version: [ 3.8, 3.9, '3.10' ] requirements-file: [ - dj22_cms40.txt, dj32_cms40.txt, + dj42_cms40.txt, ] os: [ ubuntu-20.04, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f6f84b3..59ff7c12 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,31 +4,33 @@ repos: # rev: v2.31.0 # hooks: # - id: pyupgrade -# args: ["--py37-plus"] +# args: ["--py38-plus"] # - - repo: https://github.com/adamchainz/django-upgrade - rev: '1.4.0' - hooks: - - id: django-upgrade - args: [--target-version, "2.2"] + # manually run the upgrade command to fix the issue, no need for ci to run. + # - repo: https://github.com/adamchainz/django-upgrade + # rev: '1.16.0' + # hooks: + # - id: django-upgrade + # args: [--target-version, "4.2"] - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 7.0.0 hooks: - id: flake8 - repo: https://github.com/asottile/yesqa - rev: v1.3.0 + rev: v1.5.0 hooks: - id: yesqa - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: mixed-line-ending + # upgrade the isort version to fix compatiable issue withe peotry: https://stackoverflow.com/questions/75269700/pre-commit-fails-to-install-isort-5-11-4-with-error-runtimeerror-the-poetry-co - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.13.2 hooks: - id: isort diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4587b36e..a1056c19 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,10 @@ Changelog Unreleased ========== +* add support for python 3.10 +* add support for django 4.2 +* drop support for django < 3.2 +* drop support python < 3.8 4.0.1.dev2 (2022-11-15) ======================= diff --git a/djangocms_snippet/admin.py b/djangocms_snippet/admin.py index 0b5f40de..de55dc41 100644 --- a/djangocms_snippet/admin.py +++ b/djangocms_snippet/admin.py @@ -1,5 +1,4 @@ from django.conf import settings -from django.conf.urls import url from django.contrib import admin from django.contrib.admin import helpers from django.contrib.admin.exceptions import DisallowedModelAdminToField @@ -7,6 +6,7 @@ from django.contrib.admin.utils import flatten_fieldsets, unquote from django.db import models from django.forms import Textarea +from django.urls import path from django.utils.translation import gettext as _ from cms.utils.permissions import get_model_permission_codename @@ -29,6 +29,7 @@ djangocms_versioning_enabled = False +@admin.register(Snippet) class SnippetAdmin(*snippet_admin_classes): list_display = ('name',) search_fields = ['name'] @@ -92,10 +93,10 @@ def preview_view(self, request, snippet_id=None, form_url='', extra_context=None model = self.model opts = model._meta - obj = self.get_object(request, unquote(snippet_id), to_field) + obj = self.get_object(request, unquote(str(snippet_id)), to_field) if obj is None: - return self._get_obj_does_not_exist_redirect(request, opts, snippet_id) + return self._get_obj_does_not_exist_redirect(request, opts, str(snippet_id)) fieldsets = self.get_fieldsets(request, obj) ModelForm = self.get_form( @@ -142,8 +143,8 @@ def preview_view(self, request, snippet_id=None, form_url='', extra_context=None def get_urls(self): info = self.model._meta.app_label, self.model._meta.model_name return [ - url( - r"^(?P\d+)/preview/$", + path( + "/preview/", self.admin_site.admin_view(self.preview_view), name="{}_{}_preview".format(*info), ), @@ -160,6 +161,3 @@ def has_delete_permission(self, request, obj=None): get_model_permission_codename(self.model, 'add'), ) return False - - -admin.site.register(Snippet, SnippetAdmin) diff --git a/djangocms_snippet/forms.py b/djangocms_snippet/forms.py index 0a7d1952..8a0d97b6 100644 --- a/djangocms_snippet/forms.py +++ b/djangocms_snippet/forms.py @@ -1,7 +1,7 @@ from django import forms from django.contrib import admin from django.db import transaction -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from cms.utils.urlutils import admin_reverse diff --git a/djangocms_snippet/migrations/0005_set_related_name_for_cmsplugin_ptr.py b/djangocms_snippet/migrations/0005_set_related_name_for_cmsplugin_ptr.py index 77ca9123..f27fa954 100644 --- a/djangocms_snippet/migrations/0005_set_related_name_for_cmsplugin_ptr.py +++ b/djangocms_snippet/migrations/0005_set_related_name_for_cmsplugin_ptr.py @@ -12,6 +12,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='snippetptr', name='cmsplugin_ptr', - field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='djangocms_snippet_snippetptr', serialize=False, to='cms.CMSPlugin'), + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='%(app_label)s_%(class)s', serialize=False, to='cms.cmsplugin'), ), ] diff --git a/djangocms_snippet/settings.py b/djangocms_snippet/settings.py new file mode 100644 index 00000000..c5ec3774 --- /dev/null +++ b/djangocms_snippet/settings.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +HELPER_SETTINGS = { + 'SECRET_KEY': "djangocmssnippetstestsuitekey", + 'INSTALLED_APPS': [ + 'tests.utils', + 'djangocms_versioning', + 'djangocms_snippet', + ], + 'CMS_LANGUAGES': { + 1: [{ + 'code': 'en', + 'name': 'English', + }] + }, + 'LANGUAGE_CODE': 'en', + 'ALLOWED_HOSTS': ['localhost'], + 'DJANGOCMS_SNIPPET_VERSIONING_ENABLED': True, + 'DJANGOCMS_SNIPPET_MODERATION_ENABLED': True, + 'CMS_TEMPLATES': ( + ("page.html", "Normal page"), + ), + "DEFAULT_AUTO_FIELD": "django.db.models.AutoField", +} + + +def run(): + from app_helper import runner + runner.cms('djangocms_snippet') + + +if __name__ == '__main__': + run() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..dc94fb1b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,141 @@ +[build-system] +requires = ["setuptools >= 40.6.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "djangocms-snippet" +version = "4.0.1.dev2" +authors = [ + {name = "Divio AG", email = "info@divio.ch"}, +] +maintainers = [ + {name = "Django CMS Association and contributors", email = "info@django-cms.org"} +] +license = {file = "LICENSE"} +description = "Adds snippet plugin to django CMS." +readme = "README.rst" +requires-python = ">=3.8" +dependencies = [ + 'django-cms>=4.0', +] +classifiers=[ + "Development Status :: 5 - Production/Stable", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.2", + "Framework :: Django CMS", + "Framework :: Django CMS :: 4.0", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Software Development", + "Topic :: Software Development :: Libraries", +] + +[project.optional-dependencies] +static-ace = ["djangocms-static-ace"] + +[tool.setuptools.packages.find] +where = ["djangocms_snippet"] +exclude = ["tests"] + +[project.urls] +"Bug Tracker" = "https://github.com/django-cms/djangocms-snippet/issues" +Changelog = "https://github.com/django-cms/djangocms-snippet/blob/master/CHANGELOG.rst" +Repository = "https://github.com/django-cms/djangocms-snippet" +Support = "https://www.django-cms.org/slack/" + +[tool.coverage.run] +branch = true +parallel = true +source = [ + "djangocms_snippet", + "tests", +] + +[tool.coverage.paths] +source = [ + "djangocms_snippet", + ".tox/**/site-packages", +] + +[tool.coverage.report] +show_missing = true + +[tool.mypy] +check_untyped_defs = true +disallow_any_generics = true +disallow_incomplete_defs = true +disallow_untyped_defs = true +mypy_path = "djangocms_snippet/" +no_implicit_optional = true +show_error_codes = true +warn_unreachable = true +warn_unused_ignores = true + +[[tool.mypy.overrides]] +module = "tests.*" +allow_untyped_defs = true + + +[tool.ruff] +# https://beta.ruff.rs/docs/configuration/ +line-length = 79 +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "I", # isort + "FBT", # flake8-boolean-trap + "B", # flake8-bugbear + "C", # flake8-comprehensions + "DJ", # flake8-django + "INT", # flake8-gettext + "PIE", # flake8-pie + "SIM", # flake8-simplify + "PGH", # pygrep-hooks + "PLE", # pylint error + "PLR", # pylint refactor + "PLW", # pylint warning + "UP", # pyupgrade + "C901", # mccabe + "N", # pep8-naming + "YTT", # flake8-2020, + "RUF" +] + +exclude = [ + ".eggs", + ".git", + ".mypy_cache", + ".ruff_cache", + ".env", + ".venv", + "**migrations/**", + "venv", +] + +ignore = [ + "E501", # line-too-long + "W191", # tab-indentation +] + +[tool.ruff.per-file-ignores] +"__init__.py" = [ + "F401" # unused-import +] + +[tool.ruff.isort] +combine-as-imports = true +known-first-party = [ + "djangocms_snippet", +] +extra-standard-library = ["dataclasses"] \ No newline at end of file diff --git a/requirements.in b/requirements.in new file mode 100644 index 00000000..0c959bcd --- /dev/null +++ b/requirements.in @@ -0,0 +1,6 @@ +bump2version +https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms +django-treebeard +pip-tools +pre-commit +wheel diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..c30d3b52 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,83 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile +# +asgiref==3.7.2 + # via django +build==1.1.1 + # via pip-tools +bump2version==1.0.1 + # via -r requirements.in +cfgv==3.4.0 + # via pre-commit +click==8.1.7 + # via pip-tools +distlib==0.3.8 + # via virtualenv +django==4.2.11 + # via + # django-classy-tags + # django-cms + # django-formtools + # django-sekizai + # django-treebeard + # djangocms-admin-style +django-classy-tags==4.1.0 + # via + # django-cms + # django-sekizai +django-cms @ https://github.com/django-cms/django-cms/tarball/release/4.0.1.x + # via -r requirements.in +django-formtools==2.5.1 + # via django-cms +django-sekizai==4.1.0 + # via django-cms +django-treebeard==4.7.1 + # via + # -r requirements.in + # django-cms +djangocms-admin-style==3.3.1 + # via django-cms +filelock==3.13.1 + # via virtualenv +identify==2.5.35 + # via pre-commit +nodeenv==1.8.0 + # via pre-commit +packaging==24.0 + # via + # build + # django-cms +pip-tools==7.4.1 + # via -r requirements.in +platformdirs==4.2.0 + # via virtualenv +pre-commit==3.6.2 + # via -r requirements.in +pyproject-hooks==1.0.0 + # via + # build + # pip-tools +pyyaml==6.0.1 + # via pre-commit +sqlparse==0.4.4 + # via django +tomli==2.0.1 + # via + # build + # pip-tools + # pyproject-hooks +typing-extensions==4.10.0 + # via asgiref +virtualenv==20.25.1 + # via pre-commit +wheel==0.43.0 + # via + # -r requirements.in + # pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/setup.py b/setup.py index e466fb92..de80e82e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,12 @@ #!/usr/bin/env python +import os +import sys + from setuptools import find_packages, setup -from djangocms_snippet import __version__ + +sys.path.append(os.path.dirname(os.path.abspath(__file__))) +from djangocms_snippet import __version__ # noqa:E402 REQUIREMENTS = [ @@ -18,16 +23,14 @@ 'Operating System :: OS Independent', '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', 'Framework :: Django', - 'Framework :: Django :: 2.2', - 'Framework :: Django :: 3.0', - 'Framework :: Django :: 3.1', 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.2', 'Framework :: Django CMS', + 'Framework :: Django CMS :: 4.0', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development', diff --git a/tests/requirements/base.txt b/tests/requirements/base.txt index 95b3f3f1..95964b6b 100644 --- a/tests/requirements/base.txt +++ b/tests/requirements/base.txt @@ -4,7 +4,3 @@ factory-boy flake8 isort tox - -# Unreleased django-cms 4.0 compatible packages -http://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms -https://github.com/django-cms/djangocms-versioning/tarball/master#egg=djangocms-versioning diff --git a/tests/requirements/dj22_cms40.txt b/tests/requirements/dj22_cms40.txt deleted file mode 100644 index 2f04bac0..00000000 --- a/tests/requirements/dj22_cms40.txt +++ /dev/null @@ -1,3 +0,0 @@ --r base.txt - -Django>=2.2,<3.0 diff --git a/tests/requirements/dj32_cms40.txt b/tests/requirements/dj32_cms40.txt index 7526db15..3408845a 100644 --- a/tests/requirements/dj32_cms40.txt +++ b/tests/requirements/dj32_cms40.txt @@ -1,3 +1,7 @@ -r base.txt Django>=3.2,<4.0 + +# Unreleased django 3.2 & django-cms 4.0.x compatible packages +https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms +https://github.com/django-cms/djangocms-versioning/tarball/1.2.2#egg=djangocms-versioning \ No newline at end of file diff --git a/tests/requirements/dj42_cms40.txt b/tests/requirements/dj42_cms40.txt new file mode 100644 index 00000000..96c85a01 --- /dev/null +++ b/tests/requirements/dj42_cms40.txt @@ -0,0 +1,7 @@ +-r base.txt + +Django>=4.2,<5.0 + +# Unreleased django 4.2 & django-cms 4.0.x compatible packages +https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms +https://github.com/joshyu/djangocms-versioning/tarball/feat/django-42-compatible#egg=djangocms-versioning \ No newline at end of file diff --git a/tox.ini b/tox.ini index 4d1596db..744c0de9 100644 --- a/tox.ini +++ b/tox.ini @@ -2,9 +2,7 @@ envlist = flake8 isort - py{35,36,37,38}-dj{22}-cms{37,38} - py{36,37,38}-dj{30}-cms{37,38} - py{36,37,38}-dj{31}-cms{38} + py{38,39,'3.10'}-dj{32,42}-cms{40} skip_missing_interpreters=True @@ -40,11 +38,9 @@ known_django = django [testenv] deps = -r{toxinidir}/tests/requirements/base.txt - dj22: Django>=2.2,<3.0 - dj30: Django>=3.0,<3.1 - dj31: Django>=3.1,<3.2 - cms37: django-cms>=3.7,<3.8 - cms38: django-cms>=3.8,<3.9 + dj32: Django>=3.2,<4 + dj42: Django>=4.2,<5 + cms40: django-cms>=4.0.0,<4.1 commands = {envpython} --version {env:COMMAND:coverage} erase