Skip to content

Commit

Permalink
Fix django 3.2 tests, pypi release actions and pre-commit (#594)
Browse files Browse the repository at this point in the history
* Added pypi actions

* Update manifest for private and tests. Exclude tests from setuptools

* Remove django 3.0 and EOL python.
Removed testing django 3.2 against cms 3.8
Added python 3.10 to test workflow

* Added pre-commit hooks.

* Revert changes to classifiers and remove testing against django 3.2

* Ran pre-commit hooks

* Fixed django 3.2 tests

* Update changelog

* Add pre-commit instructions to readme.

* Fix link
  • Loading branch information
marksweb authored Mar 9, 2022
1 parent a9266f2 commit ffbe35b
Show file tree
Hide file tree
Showing 31 changed files with 262 additions and 173 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: flake8
run: |
flake8 --exit-zero
run: flake8

isort:
runs-on: ubuntu-latest
Expand All @@ -37,4 +36,4 @@ jobs:
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: isort
run: isort -c -rc -df djangocms_text_ckeditor
run: isort -c -df djangocms_text_ckeditor
39 changes: 39 additions & 0 deletions .github/workflows/publish-to-live-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish Python 🐍 distributions 📦 to pypi

on:
release:
types:
- published

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish Python 🐍 distributions 📦 to TestPyPI

on:
push:
branches:
- master

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9, ] # latest release minus two
python-version: [ 3.7, 3.8, 3.9, '3.10']
requirements-file: [
dj22_cms37.txt,
dj22_cms38.txt,
dj30_cms37.txt,
dj30_cms38.txt,
dj31_cms38.txt,
dj32_cms39.txt
]
os: [
ubuntu-20.04,
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/adamchainz/django-upgrade
rev: '1.4.0'
hooks:
- id: django-upgrade
args: [--target-version, "2.2"]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-broken-line
- flake8-bugbear
- flake8-builtins
- flake8-coding
- flake8-commas
- flake8-comprehensions
- flake8-eradicate
- flake8-quotes
- flake8-tidy-imports
- pep8-naming

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
6 changes: 2 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ Unreleased
==========

* Add dark mode feature and dark mode patch for skin moono-lisa

4.0.1 (unreleased)
==================

* Added support for Django 3.2
* Drop support for python 3.5, 3.6 and django 3.0
* Added pre-commit hooks for developer workflow to ensure code quality


4.0.0 (2020-09-15)
Expand Down
16 changes: 16 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@ include README.rst
recursive-include djangocms_text_ckeditor/locale *
recursive-include djangocms_text_ckeditor/static *
recursive-include djangocms_text_ckeditor/templates *
recursive-include private/moono-lisa/dev *.png
recursive-include private/moono-lisa/dev *.svg
recursive-include private/moono-lisa/dev *.json
recursive-include private/moono-lisa/images/hidpi *.png
recursive-include private/moono-lisa/iamges *.gif
recursive-include private/moono-lisa/images *.png
recursive-include private/moono-lisa *.css
recursive-include private/moono-lisa *.js
recursive-include private/moono-lisa *.md
recursive-include private *.md
recursive-include private *.py
recursive-include tests .eslintrc
recursive-include tests *.html
recursive-include tests *.js
recursive-include tests *.py
recursive-include tests *.txt
recursive-exclude * *.py[co]
20 changes: 13 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ directly to your web pages. Enhance your website experience with our community
maintained editor. This package aims to integrate CKEditor into django CMS as
a text plugin.

.. note::
.. note::

This project is endorsed by the `django CMS Association <https://www.django-cms.org/en/about-us/>`_.
That means that it is officially accepted by the dCA as being in line with our roadmap vision and development/plugin policy.
That means that it is officially accepted by the dCA as being in line with our roadmap vision and development/plugin policy.
Join us on `Slack <https://www.django-cms.org/slack/>`_.


Expand All @@ -32,8 +32,8 @@ Contribute to this project and win rewards

Because this is a an open-source project, we welcome everyone to
`get involved in the project <https://www.django-cms.org/en/contribute/>`_ and
`receive a reward <https://www.django-cms.org/en/bounty-program/>`_ for their contribution.
Become part of a fantastic community and help us make django CMS the best CMS in the world.
`receive a reward <https://www.django-cms.org/en/bounty-program/>`_ for their contribution.
Become part of a fantastic community and help us make django CMS the best CMS in the world.

We'll be delighted to receive your
feedback in the form of issues and pull requests. Before submitting your
Expand Down Expand Up @@ -441,6 +441,13 @@ to make text content using Haystack.
Development
===========

pre-commit hooks
----------------

The repo uses pre-commit git hooks to run tools which ensure code quality.

To utilise this, run ``pip install pre-commit`` and then ``pre-commit install``.

Building the JavaScript
-----------------------

Expand All @@ -455,8 +462,7 @@ This command also updates the file name loaded based on the file contents.
Updating the CKEditor
---------------------

Make sure to use the url in `build config
<https://github.com/divio/djangocms-text-ckeditor/blob/master/djangocms_text_ckeditor/static/djangocms_text_ckeditor/ckeditor/build-config.js#L16>_`.
Make sure to use the url in `build config <https://github.com/divio/djangocms-text-ckeditor/blob/master/djangocms_text_ckeditor/static/djangocms_text_ckeditor/ckeditor/build-config.js#L16>`_.


Running Tests
Expand Down
12 changes: 6 additions & 6 deletions aldryn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ class Form(forms.BaseForm):
)

def clean(self):
data = super(Form, self).clean()
data = super().clean()

if data.get('content_css'):
files = data['content_css'].split(',')
data['content_css'] = [item.strip() for item in files if item]
return data

def to_settings(self, data, settings):
CKEDITOR_SETTINGS = {
ckeditor_settings = {
'height': 300,
'language': '{{ language }}',
'toolbar': 'CMS',
'skin': 'moono-lisa',
}

if data.get('content_css'):
CKEDITOR_SETTINGS['contentsCss'] = data['content_css']
ckeditor_settings['contentsCss'] = data['content_css']
else:
CKEDITOR_SETTINGS['contentsCss'] = ['/static/css/base.css']
ckeditor_settings['contentsCss'] = ['/static/css/base.css']

if data.get('style_set'):
style_set = data['style_set']
else:
style_set = ''

CKEDITOR_SETTINGS['stylesSet'] = 'default:{}'.format(style_set)
ckeditor_settings['stylesSet'] = f'default:{style_set}'

settings['CKEDITOR_SETTINGS'] = CKEDITOR_SETTINGS
settings['CKEDITOR_SETTINGS'] = ckeditor_settings
return settings
25 changes: 9 additions & 16 deletions djangocms_text_ckeditor/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from django.core.exceptions import PermissionDenied, ValidationError
from django.db import transaction
from django.forms.fields import CharField
from django.http import (
Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden,
HttpResponseRedirect,
)
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.template import RequestContext
from django.urls import re_path, reverse
Expand All @@ -28,15 +25,11 @@
from cms.utils.urlutils import admin_reverse

from . import settings
from .forms import (
ActionTokenValidationForm, DeleteOnCancelForm, RenderPluginForm, TextForm,
)
from .forms import ActionTokenValidationForm, DeleteOnCancelForm, RenderPluginForm, TextForm
from .models import Text
from .utils import (
OBJ_ADMIN_WITH_CONTENT_RE_PATTERN, _plugin_tags_to_html,
plugin_tags_to_admin_html, plugin_tags_to_id_list,
plugin_tags_to_user_html, plugin_to_tag, random_comment_exempt,
replace_plugin_tags,
OBJ_ADMIN_WITH_CONTENT_RE_PATTERN, _plugin_tags_to_html, plugin_tags_to_admin_html, plugin_tags_to_id_list,
plugin_tags_to_user_html, plugin_to_tag, random_comment_exempt, replace_plugin_tags,
)
from .widgets import TextEditorWidget

Expand Down Expand Up @@ -193,11 +186,11 @@ class TextPlugin(CMSPluginBase):
_has_do_post_copy = True

@classmethod
def do_post_copy(self, instance, source_map):
def do_post_copy(cls, instance, source_map):
ids = plugin_tags_to_id_list(instance.body)
ids_map = {pk: source_map[pk].pk for pk in ids if pk in source_map}
new_text = replace_plugin_tags(instance.body, ids_map)
self.model.objects.filter(pk=instance.pk).update(body=new_text)
cls.model.objects.filter(pk=instance.pk).update(body=new_text)

@staticmethod
def get_translation_export_content(field, plugin_data):
Expand Down Expand Up @@ -329,7 +322,7 @@ def add_view(self, request, form_url='', extra_context=None):
# The instance is a record that points to the Text plugin
# but is not a real text plugin instance.
return super().add_view(
request, form_url, extra_context
request, form_url, extra_context,
)

if not self.has_add_permission(request):
Expand Down Expand Up @@ -395,7 +388,7 @@ def pattern(regex, func):

def get_admin_url_name(self, name):
plugin_type = self.__class__.__name__.lower()
url_name = '%s_%s_%s' % (self.model._meta.app_label, plugin_type, name)
url_name = f'{self.model._meta.app_label}_{plugin_type}_{name}'
return url_name

def _get_text_plugin_from_request(self, request, data):
Expand Down Expand Up @@ -513,7 +506,7 @@ def render(self, context, instance, placeholder):
context,
),
'placeholder': placeholder,
'object': instance
'object': instance,
})
return context

Expand Down
14 changes: 7 additions & 7 deletions djangocms_text_ckeditor/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _filter_kwargs():
for attr in settings.TEXT_ADDITIONAL_ATTRIBUTES
),
'allowed_protocols': sanitizer.allowed_protocols | frozenset(
settings.TEXT_ADDITIONAL_PROTOCOLS
settings.TEXT_ADDITIONAL_PROTOCOLS,
),
})
return kwargs
Expand All @@ -46,7 +46,7 @@ def _get_default_parser():
for parser_class in settings.ALLOW_TOKEN_PARSERS:
parser_classes.append(import_string(parser_class))
TextSanitizer.allow_token_parsers = parser_classes
return html5lib.HTMLParser(tree=treebuilders.getTreeBuilder("dom"))
return html5lib.HTMLParser(tree=treebuilders.getTreeBuilder('dom'))


DEFAULT_PARSER = _get_default_parser()
Expand All @@ -73,7 +73,7 @@ def clean_html(data, full=True, parser=DEFAULT_PARSER):
omit_optional_tags=False,
quote_attr_values='always',
)
return u''.join(s.serialize(stream))
return ''.join(s.serialize(stream))


def extract_images(data, plugin):
Expand Down Expand Up @@ -127,26 +127,26 @@ def extract_images(data, plugin):
im.save(new_image, 'JPEG')
new_image.seek(0)
image = new_image
filename = u'%s.%s' % (uuid.uuid4(), file_ending)
filename = f'{uuid.uuid4()}.{file_ending}'
# transform image into a cms plugin
image_plugin = img_data_to_plugin(
filename, image, parent_plugin=plugin, width=width, height=height
filename, image, parent_plugin=plugin, width=width, height=height,
)
# render the new html for the plugin
new_img_html = plugin_to_tag(image_plugin)
# replace the original image node with the newly created cms plugin html
img.parentNode.replaceChild(parser.parseFragment(new_img_html).childNodes[0], img)
found = True
if found:
return u''.join([y.toxml() for y in dom.getElementsByTagName('body')[0].childNodes])
return ''.join([y.toxml() for y in dom.getElementsByTagName('body')[0].childNodes])
else:
return data


def img_data_to_plugin(filename, image, parent_plugin, width=None, height=None):
func_name = settings.TEXT_SAVE_IMAGE_FUNCTION.split('.')[-1]
module = __import__(
'.'.join(settings.TEXT_SAVE_IMAGE_FUNCTION.split('.')[:-1]), fromlist=[func_name]
'.'.join(settings.TEXT_SAVE_IMAGE_FUNCTION.split('.')[:-1]), fromlist=[func_name],
)
func = getattr(module, func_name)
return func(filename, image, parent_plugin, width=width, height=height)
Loading

0 comments on commit ffbe35b

Please sign in to comment.