From a7fecf565d21e5264020530561bb8d7e8dd0972f Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 11:49:30 +0100 Subject: [PATCH 1/9] Updated package configuration from maykinmedia/default-app --- .github/workflows/ci.yml | 64 +++++++++++++++++++ .github/workflows/code_quality.yml | 33 ++++++++++ .travis.yml | 29 --------- License => LICENSE | 0 MANIFEST.in | 2 + setup.py => _old_setup.py | 0 pyproject.toml | 98 ++++++++++++++++++++++++++++++ setup.cfg | 6 +- tox.ini | 79 ++++++++++++++++-------- 9 files changed, 254 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/code_quality.yml delete mode 100644 .travis.yml rename License => LICENSE (100%) rename setup.py => _old_setup.py (100%) create mode 100644 pyproject.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c655b7f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: Run CI + +# Run this workflow every time a new commit pushed to your repository +on: + push: + branches: + - master + tags: + - '*' + pull_request: + workflow_dispatch: + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.10', '3.11', '3.12'] + django: ['4.2'] + + name: Run the test suite (Python $, Django $) + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: $ + + - name: Install dependencies + run: pip install tox tox-gh-actions + + - name: Run tests + run: tox + env: + PYTHON_VERSION: $ + DJANGO: $ + + - name: Publish coverage report + uses: codecov/codecov-action@v3 + + publish: + name: Publish package to PyPI + runs-on: ubuntu-latest + needs: tests + + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Build sdist and wheel + run: | + pip install build --upgrade + python -m build + + # TODO: switch to verified publishers + - name: Publish a Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: $ diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml new file mode 100644 index 0000000..6fa948e --- /dev/null +++ b/.github/workflows/code_quality.yml @@ -0,0 +1,33 @@ +name: Code quality checks + +# Run this workflow every time a new commit pushed to your repository +on: + push: + branches: + - master + tags: + - '*' + paths: + - '**.py' + pull_request: + paths: + - '**.py' + workflow_dispatch: + +jobs: + linting: + name: Code-quality checks + runs-on: ubuntu-latest + strategy: + matrix: + toxenv: [isort, black, flake8, docs] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Install dependencies + run: pip install tox + - run: tox + env: + TOXENV: $ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 37c136c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: python -python: - - "3.5" - -services: - - postgresql - -addons: - postgresql: "9.4" - -install: - - pip install codecov coveralls tox -script: - - tox -- -after_success: - - coveralls - - codecov -env: - - TOXENV=py27-django18 - - TOXENV=py34-django18 - - TOXENV=py35-django18 - - - TOXENV=py27-django19 - - TOXENV=py34-django19 - - TOXENV=py35-django19 - - - TOXENV=py27-django110 - - TOXENV=py34-django110 - - TOXENV=py35-django110 diff --git a/License b/LICENSE similarity index 100% rename from License rename to LICENSE diff --git a/MANIFEST.in b/MANIFEST.in index ba979f0..aa032d0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,3 +2,5 @@ include License include README.rst recursive-include mail_editor/templates * recursive-include bin * +global-exclude __pycache__ +global-exclude *.py[co] diff --git a/setup.py b/_old_setup.py similarity index 100% rename from setup.py rename to _old_setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3ba3e25 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,98 @@ +[build-system] +requires = ["setuptools>=61.0.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "mail_editor" +version = "0.3.6" +description = "A Django package for email template editing" +authors = [ + {name = "Maykin Media", email = "support@maykinmedia.nl"} +] +readme = "README.rst" +license = {file = "LICENSE"} +keywords = ["TODO"] +classifiers = [ + "Development Status :: 3 - Alpha", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.2", + "Intended Audience :: Developers", + "Operating System :: Unix", + "Operating System :: MacOS", + "Operating System :: Microsoft :: Windows", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Software Development :: Libraries :: Python Modules", +] +requires-python = ">=3.10" +dependencies = [ + "django>=4.2", + "django-choices", + "django-ckeditor", + "requests", + "lxml", + "css_inline" +] + +[project.urls] +Homepage = "https://github.com/maykinmedia/mail-editor" +Documentation = "http://mail_editor.readthedocs.io/en/latest/" +"Bug Tracker" = "https://github.com/maykinmedia/mail-editor/issues" +"Source Code" = "https://github.com/maykinmedia/mail-editor" + +[project.optional-dependencies] +tests = [ + "pytest", + "pytest-django", + "tox", + "isort", + "black", + "flake8", +] +coverage = [ + "pytest-cov", +] +docs = [ + "sphinx", + "sphinx-rtd-theme", +] +release = [ + "bump-my-version", + "twine", +] + +[tool.setuptools.packages.find] +include = ["mail_editor*"] +namespaces = false + +[tool.isort] +profile = "black" +combine_as_imports = true +known_django = "django" +known_first_party="mail_editor" +sections=["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] + +[tool.pytest.ini_options] +testpaths = ["tests"] +DJANGO_SETTINGS_MODULE = "testapp.settings" + +[tool.bumpversion] +current_version = "0.3.5" +files = [ + {filename = "pyproject.toml"}, + {filename = "README.rst"}, + {filename = "docs/conf.py"}, +] + +[tool.coverage.report] +exclude_also = [ + "if (typing\\.)?TYPE_CHECKING:", + "@(typing\\.)?overload", + "class .*\\(.*Protocol.*\\):", + "@(abc\\.)?abstractmethod", + "raise NotImplementedError", + "\\.\\.\\.", + "pass", +] diff --git a/setup.cfg b/setup.cfg index 288390b..a3d1a49 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,11 +6,13 @@ universal=1 [pep8] ignore=W293,W291,E501,E261 - max-line-length=120 - exclude=migrations,static,media +[flake8] +max-line-length=120 +exclude=env,.tox,doc + [isort] combine_as_imports = true default_section = THIRDPARTY diff --git a/tox.ini b/tox.ini index 8b24d8d..77bf28d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,34 +1,61 @@ [tox] -envlist = py{27,34,35,py}-django{18,19,110},isort +envlist = + py{310,311,312}-django{32,42} + isort + black + flake8 + docs skip_missing_interpreters = true +[gh-actions] +python = + 3.10: py310 + 3.11: py311 + 3.12: py312 + +[gh-actions:env] +DJANGO = + 3.2: django32 + 4.2: django42 + [testenv] +setenv = + DJANGO_SETTINGS_MODULE=testapp.settings + PYTHONPATH={toxinidir} +extras = + tests + coverage deps = - factory-boy - mock - psycopg2 - pytest - pytest-cov - pytest-django - pytest-pep8 - pytest-pylint - pytest-pythonpath - pytest-runner - django18: Django>=1.8,<1.9 - django19: Django>=1.9,<1.10 - django110: Django>=1.10,<1.11 -commands= - py.test \ - --cov-report=xml \ - --cov=mail_editor \ - --verbose \ - --junit-xml=junit.xml \ - --color=yes \ - tests \ - {posargs} - + django42: Django~=4.2.0 + django32: Django~=3.2.0 +commands = + py.test tests \ + --cov --cov-report xml:reports/coverage-{envname}.xml \ + {posargs} [testenv:isort] -deps = isort +extras = tests +skipsdist = True +commands = isort --check-only --diff . + +[testenv:black] +extras = tests +skipsdist = True +commands = black --check mail_editor docs testapp tests + +[testenv:flake8] +extras = tests skipsdist = True -commands = isort --recursive --check-only --diff mail_editor +commands = flake8 . + +[testenv:docs] +basepython=python +changedir=docs +skipsdist=true +extras = + tests + docs +commands= + py.test check_sphinx.py -v \ + --tb=auto \ + {posargs} From b525e77f8fd3792a882020b9cae1f153cd9b8927 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 12:43:15 +0100 Subject: [PATCH 2/9] Dropped some outdated info from README.rst --- README.rst | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 73ebd0a..0cf7fd9 100644 --- a/README.rst +++ b/README.rst @@ -1,18 +1,9 @@ MailEditor ========== -.. image:: https://travis-ci.org/maykinmedia/mail-editor.svg?branch=master - :target: https://travis-ci.org/maykinmedia/mail-editor - :alt: Travis .. image:: https://codecov.io/gh/maykinmedia/mail-editor/branch/develop/graph/badge.svg :target: https://codecov.io/gh/maykinmedia/mail-editor :alt: Coverage -.. image:: https://lintly.com/gh/maykinmedia/mail-editor/badge.svg - :target: https://lintly.com/gh/maykinmedia/mail-editor/ - :alt: Lintly -.. image:: https://bettercodehub.com/edge/badge/maykinmedia/mail-editor?branch=master - :target: https://bettercodehub.com/results/maykinmedia/mail-editor - :alt: BCH compliance .. image:: https://codeclimate.com/github/codeclimate/codeclimate/badges/gpa.svg :target: https://codeclimate.com/github/codeclimate/codeclimate :alt: Code Climate @@ -39,10 +30,10 @@ For e-mail sending and logging, we recommend using a solution such as `Django Yu This is only tested on a postgres database. -Supported (read: Travis tested) are: +Supported are: -- python 2.7, 3.4, 3.5 -- Django 1.8, 1.9, 1.10, 1.11 +- python 3.10, 3.11, 3.12 +- Django 3.2, 4.2 - PostgreSQL Warning @@ -120,8 +111,8 @@ The following settings are an example: MAIL_EDITOR_CONF = { 'activation': { - 'name': ugettext_noop('Activation Email'), - 'description': ugettext_noop('This email is used when people need to activate their account.'), + 'name': gettext_noop('Activation Email'), + 'description': gettext_noop('This email is used when people need to activate their account.'), 'subject_default': 'Activeer uw account voor {{site_name}}', 'body_default': """

Hallo {{ name }},

@@ -132,21 +123,21 @@ The following settings are an example: """, 'subject': [{ 'name': 'site_name', - 'description': ugettext_noop('This is the name of the site. From the sites'), - 'example': ugettext_noop('Example site'), + 'description': gettext_noop('This is the name of the site. From the sites'), + 'example': gettext_noop('Example site'), }], 'body': [{ 'name': 'name', - 'description': ugettext_noop('This is the name of the user'), - 'example': ugettext_noop('Jane Doe'), + 'description': gettext_noop('This is the name of the user'), + 'example': gettext_noop('Jane Doe'), }, { 'name': 'site_name', - 'description': ugettext_noop('This is the name of the site. From the sites'), - 'example': ugettext_noop('Example site'), + 'description': gettext_noop('This is the name of the site. From the sites'), + 'example': gettext_noop('Example site'), }, { 'name': 'activation_link', - 'description': ugettext_noop('This is the link to activate their account.'), - 'example': ugettext_noop('/'), + 'description': gettext_noop('This is the link to activate their account.'), + 'example': gettext_noop('/'), }] }, ... From 41049276a9193e6842d1800d87d41e7e67d4a1d7 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 12:48:57 +0100 Subject: [PATCH 3/9] Fixed Github workflow variables breaking from scaffolding default-app --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/code_quality.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c655b7f..9330d1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,13 +18,13 @@ jobs: python: ['3.10', '3.11', '3.12'] django: ['4.2'] - name: Run the test suite (Python $, Django $) + name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }}) steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: $ + python-version: ${{ matrix.python }} - name: Install dependencies run: pip install tox tox-gh-actions @@ -32,8 +32,8 @@ jobs: - name: Run tests run: tox env: - PYTHON_VERSION: $ - DJANGO: $ + PYTHON_VERSION: ${{ matrix.python }} + DJANGO: ${{ matrix.django }} - name: Publish coverage report uses: codecov/codecov-action@v3 @@ -61,4 +61,4 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ - password: $ + password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 6fa948e..ea7bf9b 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -30,4 +30,4 @@ jobs: run: pip install tox - run: tox env: - TOXENV: $ + TOXENV: ${{ matrix.toxenv }} From 373602d3e55d872dc864bb2360172bda041edc0e Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 13:06:16 +0100 Subject: [PATCH 4/9] Fixes for Github workflow --- .github/workflows/ci.yml | 2 +- docs/Makefile | 20 +++++++++++++ docs/check_sphinx.py | 17 +++++++++++ docs/conf.py | 61 ++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 60 +++++++++++++++++++++++++++++++++++++++ docs/quickstart.rst | 18 ++++++++++++ fix.sh | 2 ++ pyproject.toml | 6 ++-- tox.ini | 4 +-- 9 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 docs/Makefile create mode 100644 docs/check_sphinx.py create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/quickstart.rst diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9330d1b..b6fcb12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: python: ['3.10', '3.11', '3.12'] - django: ['4.2'] + django: ['3.2', '4.2'] name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }}) diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/check_sphinx.py b/docs/check_sphinx.py new file mode 100644 index 0000000..cc1003a --- /dev/null +++ b/docs/check_sphinx.py @@ -0,0 +1,17 @@ +import subprocess + + +def test_linkcheck(tmpdir): + doctrees = tmpdir.join("doctrees") + htmldir = tmpdir.join("html") + subprocess.check_call( + ["sphinx-build", "-W", "-blinkcheck", "-d", str(doctrees), ".", str(htmldir)], + ) + + +def test_build_docs(tmpdir): + doctrees = tmpdir.join("doctrees") + htmldir = tmpdir.join("html") + subprocess.check_call( + ["sphinx-build", "-W", "-bhtml", "-d", str(doctrees), ".", str(htmldir)], + ) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..cafa1bf --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,61 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import sys +from pathlib import Path + +current_dir = Path(__file__).parents[1] +code_directory = current_dir / "mail_editor" + +sys.path.insert(0, str(code_directory)) + + +# -- Project information ----------------------------------------------------- + +project = "mail_editor" +copyright = "2024, Maykin Media" +author = "Maykin Media" + +# The full version, including alpha/beta/rc tags +release = "0.1.0" + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named "sphinx.ext.*") or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.todo", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = [] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..b7d7b05 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,60 @@ +.. mail_editor documentation master file, created by startproject. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to mail_editor's documentation! +================================================= + +|build-status| |code-quality| |black| |coverage| |docs| + +|python-versions| |django-versions| |pypi-version| + + + +Features +======== + +* ... +* ... + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + quickstart + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + + +.. |build-status| image:: https://github.com/maykinmedia/mail_editor/workflows/Run%20CI/badge.svg + :alt: Build status + :target: https://github.com/maykinmedia/mail_editor/actions?query=workflow%3A%22Run+CI%22 + +.. |code-quality| image:: https://github.com/maykinmedia/mail_editor/workflows/Code%20quality%20checks/badge.svg + :alt: Code quality checks + :target: https://github.com/maykinmedia/mail_editor/actions?query=workflow%3A%22Code+quality+checks%22 + +.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + +.. |coverage| image:: https://codecov.io/gh/maykinmedia/mail_editor/branch/master/graph/badge.svg + :target: https://codecov.io/gh/maykinmedia/mail_editor + :alt: Coverage status + +.. |docs| image:: https://readthedocs.org/projects/mail_editor/badge/?version=latest + :target: https://mail_editor.readthedocs.io/en/latest/?badge=latest + :alt: Documentation Status + +.. |python-versions| image:: https://img.shields.io/pypi/pyversions/mail_editor.svg + +.. |django-versions| image:: https://img.shields.io/pypi/djversions/mail_editor.svg + +.. |pypi-version| image:: https://img.shields.io/pypi/v/mail_editor.svg + :target: https://pypi.org/project/mail_editor/ diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 0000000..af6c472 --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,18 @@ +========== +Quickstart +========== + +Installation +============ + +Install from PyPI with pip: + +.. code-block:: bash + + pip install mail_editor + + +Usage +===== + + diff --git a/fix.sh b/fix.sh index fdb2e72..9e1d041 100755 --- a/fix.sh +++ b/fix.sh @@ -7,3 +7,5 @@ black ./mail_editor isort --profile black ./tests autoflake --in-place --remove-all-unused-imports -r ./tests black ./tests + +black ./docs diff --git a/pyproject.toml b/pyproject.toml index 3ba3e25..a57c2ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ ] requires-python = ">=3.10" dependencies = [ - "django>=4.2", + "django>=3.2", "django-choices", "django-ckeditor", "requests", @@ -50,6 +50,8 @@ tests = [ "isort", "black", "flake8", + "autoflake", + "django_webtest", ] coverage = [ "pytest-cov", @@ -76,7 +78,7 @@ sections=["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER [tool.pytest.ini_options] testpaths = ["tests"] -DJANGO_SETTINGS_MODULE = "testapp.settings" +DJANGO_SETTINGS_MODULE = "tests.settings" [tool.bumpversion] current_version = "0.3.5" diff --git a/tox.ini b/tox.ini index 77bf28d..df1515b 100644 --- a/tox.ini +++ b/tox.ini @@ -20,7 +20,7 @@ DJANGO = [testenv] setenv = - DJANGO_SETTINGS_MODULE=testapp.settings + DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH={toxinidir} extras = tests @@ -41,7 +41,7 @@ commands = isort --check-only --diff . [testenv:black] extras = tests skipsdist = True -commands = black --check mail_editor docs testapp tests +commands = black --check mail_editor docs tests [testenv:flake8] extras = tests From 3fe96ed371bf49d29779ef32993cc790e5e0170e Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 13:20:36 +0100 Subject: [PATCH 5/9] Fixed actual Django compatibility issues from test matrix --- tests/test_send.py | 2 +- tests/test_template_rendering.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_send.py b/tests/test_send.py index b227d46..96a923f 100644 --- a/tests/test_send.py +++ b/tests/test_send.py @@ -3,7 +3,7 @@ from django.core import mail from django.test import TestCase, override_settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from mail_editor.helpers import find_template diff --git a/tests/test_template_rendering.py b/tests/test_template_rendering.py index a3546ac..edcee0c 100644 --- a/tests/test_template_rendering.py +++ b/tests/test_template_rendering.py @@ -41,7 +41,7 @@ def test_simple(self): subject, body = template.render(body_context, subj_context=subject_context) - self.assertEquals(subject, "Important message for 111") + self.assertEqual(subject, "Important message for 111") self.assertIn("Test mail sent from testcase with 111", body) @override_settings(MAIL_EDITOR_CONF=CONFIG, MAIL_EDITOR_BASE_CONTEXT={"id": "BASE"}) @@ -53,7 +53,7 @@ def test_base_context(self): subject, body = template.render(body_context, subj_context=subject_context) - self.assertEquals(subject, "Important message for BASE") + self.assertEqual(subject, "Important message for BASE") self.assertIn("Test mail sent from testcase with BASE", body) @override_settings( @@ -68,7 +68,7 @@ def test_dynamic_context(self): subject, body = template.render(body_context, subj_context=subject_context) - self.assertEquals(subject, "Important message for DYNAMIC") + self.assertEqual(subject, "Important message for DYNAMIC") self.assertIn("Test mail sent from testcase with DYNAMIC", body) @override_settings(MAIL_EDITOR_CONF=CONFIG) @@ -81,7 +81,7 @@ def test_incorrect_base_path(self): subject, body = template.render(body_context, subj_context=subject_context) - self.assertEquals(subject, "Important message for 222") + self.assertEqual(subject, "Important message for 222") self.assertIn("Test mail sent from testcase with 222", body) @override_settings(MAIL_EDITOR_CONF=CONFIG) @@ -98,7 +98,7 @@ def test_base_template_errors(self): subject, body = template.render(body_context, subj_context=subject_context) - self.assertEquals(subject, "Important message for 333") + self.assertEqual(subject, "Important message for 333") self.assertIn("Test mail sent from testcase with 333", body) @override_settings(MAIL_EDITOR_CONF=CONFIG) @@ -110,6 +110,6 @@ def test_render_preview(self): subject, body = template.render(body_context, subj_context=subject_context) # rendered placeholder - self.assertEquals(subject, "Important message for --id--") + self.assertEqual(subject, "Important message for --id--") # rendered example self.assertIn("Test mail sent from testcase with 321", body) From ba05e00bc14567b6e4fce56545d6350b44babb24 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 13:43:01 +0100 Subject: [PATCH 6/9] Fixed or silenced flake8 issues --- mail_editor/mail_template.py | 9 ++++----- setup.cfg | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mail_editor/mail_template.py b/mail_editor/mail_template.py index d8fb3b1..5cf581f 100644 --- a/mail_editor/mail_template.py +++ b/mail_editor/mail_template.py @@ -2,8 +2,6 @@ Defines helpers for validating e-mail templates """ -from __future__ import absolute_import, unicode_literals - from django.core.exceptions import ValidationError from django.template import ( # TODO: should be able to specify engine Context, @@ -63,7 +61,8 @@ def check_syntax_errors(self, value): def check_variables(self, template, field): variables_seen = set() required_vars = {var.name for var in self.config[field] if var.required} - optional_vars = {var.name for var in self.config[field] if not var.required} + # TODO do we need to check optional_vars? the following line was here but never used + # optional_vars = {var.name for var in self.config[field] if not var.required} for node in template.nodelist.get_nodes_by_type(VariableNode): var_name = node.filter_expression.var.var variables_seen.add(var_name) @@ -80,8 +79,8 @@ def check_variables(self, template, field): params={field: message}, message=message, code=self.code ) - def _is_attribute(self, vars, known_vars): - for var in vars: + def _is_attribute(self, var_names, known_vars): + for var in var_names: if any(var.startswith("{}.".format(known_var)) for known_var in known_vars): return True diff --git a/setup.cfg b/setup.cfg index a3d1a49..48f354c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,8 +10,9 @@ max-line-length=120 exclude=migrations,static,media [flake8] +ignore=E203,E261,E501,E731,F405,W293,W291,W503,F841,E741 max-line-length=120 -exclude=env,.tox,doc +exclude=env,.tox,docs [isort] combine_as_imports = true From 2e297c06f20c07d935815c8be97b96e789a1fecc Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Wed, 28 Feb 2024 13:52:52 +0100 Subject: [PATCH 7/9] Fixed/silenced docs check issues --- .github/workflows/code_quality.yml | 3 ++- docs/conf.py | 2 +- docs/index.rst | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index ea7bf9b..0cc5c96 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -20,7 +20,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toxenv: [isort, black, flake8, docs] + # toxenv: [isort, black, flake8, docs] + toxenv: [isort, black, flake8] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/docs/conf.py b/docs/conf.py index cafa1bf..a62e164 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -26,7 +26,7 @@ author = "Maykin Media" # The full version, including alpha/beta/rc tags -release = "0.1.0" +release = "0.3.5" # -- General configuration --------------------------------------------------- diff --git a/docs/index.rst b/docs/index.rst index b7d7b05..e900510 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,8 +1,8 @@ -.. mail_editor documentation master file, created by startproject. +.. mail-editor documentation master file, created by startproject. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -Welcome to mail_editor's documentation! +Welcome to mail-editor's documentation! ================================================= |build-status| |code-quality| |black| |coverage| |docs| @@ -33,28 +33,28 @@ Indices and tables * :ref:`search` -.. |build-status| image:: https://github.com/maykinmedia/mail_editor/workflows/Run%20CI/badge.svg +.. |build-status| image:: https://github.com/maykinmedia/mail-editor/workflows/Run%20CI/badge.svg :alt: Build status - :target: https://github.com/maykinmedia/mail_editor/actions?query=workflow%3A%22Run+CI%22 + :target: https://github.com/maykinmedia/mail-editor/actions?query=workflow%3A%22Run+CI%22 -.. |code-quality| image:: https://github.com/maykinmedia/mail_editor/workflows/Code%20quality%20checks/badge.svg +.. |code-quality| image:: https://github.com/maykinmedia/mail-editor/workflows/Code%20quality%20checks/badge.svg :alt: Code quality checks - :target: https://github.com/maykinmedia/mail_editor/actions?query=workflow%3A%22Code+quality+checks%22 + :target: https://github.com/maykinmedia/mail-editor/actions?query=workflow%3A%22Code+quality+checks%22 .. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black -.. |coverage| image:: https://codecov.io/gh/maykinmedia/mail_editor/branch/master/graph/badge.svg - :target: https://codecov.io/gh/maykinmedia/mail_editor +.. |coverage| image:: https://codecov.io/gh/maykinmedia/mail-editor/branch/master/graph/badge.svg + :target: https://codecov.io/gh/maykinmedia/mail-editor :alt: Coverage status -.. |docs| image:: https://readthedocs.org/projects/mail_editor/badge/?version=latest - :target: https://mail_editor.readthedocs.io/en/latest/?badge=latest +.. |docs| image:: https://readthedocs.org/projects/mail-editor/badge/?version=latest + :target: https://mail-editor.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status -.. |python-versions| image:: https://img.shields.io/pypi/pyversions/mail_editor.svg +.. |python-versions| image:: https://img.shields.io/pypi/pyversions/mail-editor.svg -.. |django-versions| image:: https://img.shields.io/pypi/djversions/mail_editor.svg +.. |django-versions| image:: https://img.shields.io/pypi/djversions/mail-editor.svg -.. |pypi-version| image:: https://img.shields.io/pypi/v/mail_editor.svg - :target: https://pypi.org/project/mail_editor/ +.. |pypi-version| image:: https://img.shields.io/pypi/v/mail-editor.svg + :target: https://pypi.org/project/mail-editor/ From ccbcf41440162a49f38488fbedfee8630ccc1785 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Thu, 29 Feb 2024 09:08:57 +0100 Subject: [PATCH 8/9] Dropped docs support --- docs/Makefile | 20 --------------- docs/check_sphinx.py | 17 ------------ docs/conf.py | 61 -------------------------------------------- docs/index.rst | 60 ------------------------------------------- docs/quickstart.rst | 18 ------------- pyproject.toml | 7 +---- setup.cfg | 2 +- tox.ini | 15 +---------- 8 files changed, 3 insertions(+), 197 deletions(-) delete mode 100644 docs/Makefile delete mode 100644 docs/check_sphinx.py delete mode 100644 docs/conf.py delete mode 100644 docs/index.rst delete mode 100644 docs/quickstart.rst diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index d4bb2cb..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -SOURCEDIR = . -BUILDDIR = _build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/check_sphinx.py b/docs/check_sphinx.py deleted file mode 100644 index cc1003a..0000000 --- a/docs/check_sphinx.py +++ /dev/null @@ -1,17 +0,0 @@ -import subprocess - - -def test_linkcheck(tmpdir): - doctrees = tmpdir.join("doctrees") - htmldir = tmpdir.join("html") - subprocess.check_call( - ["sphinx-build", "-W", "-blinkcheck", "-d", str(doctrees), ".", str(htmldir)], - ) - - -def test_build_docs(tmpdir): - doctrees = tmpdir.join("doctrees") - htmldir = tmpdir.join("html") - subprocess.check_call( - ["sphinx-build", "-W", "-bhtml", "-d", str(doctrees), ".", str(htmldir)], - ) diff --git a/docs/conf.py b/docs/conf.py deleted file mode 100644 index a62e164..0000000 --- a/docs/conf.py +++ /dev/null @@ -1,61 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -import sys -from pathlib import Path - -current_dir = Path(__file__).parents[1] -code_directory = current_dir / "mail_editor" - -sys.path.insert(0, str(code_directory)) - - -# -- Project information ----------------------------------------------------- - -project = "mail_editor" -copyright = "2024, Maykin Media" -author = "Maykin Media" - -# The full version, including alpha/beta/rc tags -release = "0.3.5" - - -# -- General configuration --------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named "sphinx.ext.*") or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.todo", -] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] - - -# -- Options for HTML output ------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = "sphinx_rtd_theme" - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = [] diff --git a/docs/index.rst b/docs/index.rst deleted file mode 100644 index e900510..0000000 --- a/docs/index.rst +++ /dev/null @@ -1,60 +0,0 @@ -.. mail-editor documentation master file, created by startproject. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to mail-editor's documentation! -================================================= - -|build-status| |code-quality| |black| |coverage| |docs| - -|python-versions| |django-versions| |pypi-version| - - - -Features -======== - -* ... -* ... - -.. toctree:: - :maxdepth: 2 - :caption: Contents: - - quickstart - - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` - - -.. |build-status| image:: https://github.com/maykinmedia/mail-editor/workflows/Run%20CI/badge.svg - :alt: Build status - :target: https://github.com/maykinmedia/mail-editor/actions?query=workflow%3A%22Run+CI%22 - -.. |code-quality| image:: https://github.com/maykinmedia/mail-editor/workflows/Code%20quality%20checks/badge.svg - :alt: Code quality checks - :target: https://github.com/maykinmedia/mail-editor/actions?query=workflow%3A%22Code+quality+checks%22 - -.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - -.. |coverage| image:: https://codecov.io/gh/maykinmedia/mail-editor/branch/master/graph/badge.svg - :target: https://codecov.io/gh/maykinmedia/mail-editor - :alt: Coverage status - -.. |docs| image:: https://readthedocs.org/projects/mail-editor/badge/?version=latest - :target: https://mail-editor.readthedocs.io/en/latest/?badge=latest - :alt: Documentation Status - -.. |python-versions| image:: https://img.shields.io/pypi/pyversions/mail-editor.svg - -.. |django-versions| image:: https://img.shields.io/pypi/djversions/mail-editor.svg - -.. |pypi-version| image:: https://img.shields.io/pypi/v/mail-editor.svg - :target: https://pypi.org/project/mail-editor/ diff --git a/docs/quickstart.rst b/docs/quickstart.rst deleted file mode 100644 index af6c472..0000000 --- a/docs/quickstart.rst +++ /dev/null @@ -1,18 +0,0 @@ -========== -Quickstart -========== - -Installation -============ - -Install from PyPI with pip: - -.. code-block:: bash - - pip install mail_editor - - -Usage -===== - - diff --git a/pyproject.toml b/pyproject.toml index a57c2ad..b1a8e60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ [project.urls] Homepage = "https://github.com/maykinmedia/mail-editor" -Documentation = "http://mail_editor.readthedocs.io/en/latest/" +Documentation = "https://github.com/maykinmedia/mail-editor" "Bug Tracker" = "https://github.com/maykinmedia/mail-editor/issues" "Source Code" = "https://github.com/maykinmedia/mail-editor" @@ -56,10 +56,6 @@ tests = [ coverage = [ "pytest-cov", ] -docs = [ - "sphinx", - "sphinx-rtd-theme", -] release = [ "bump-my-version", "twine", @@ -85,7 +81,6 @@ current_version = "0.3.5" files = [ {filename = "pyproject.toml"}, {filename = "README.rst"}, - {filename = "docs/conf.py"}, ] [tool.coverage.report] diff --git a/setup.cfg b/setup.cfg index 48f354c..b4bb161 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,7 @@ exclude=migrations,static,media [flake8] ignore=E203,E261,E501,E731,F405,W293,W291,W503,F841,E741 max-line-length=120 -exclude=env,.tox,docs +exclude=env,.tox [isort] combine_as_imports = true diff --git a/tox.ini b/tox.ini index df1515b..fd3f690 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,6 @@ envlist = isort black flake8 - docs skip_missing_interpreters = true [gh-actions] @@ -41,21 +40,9 @@ commands = isort --check-only --diff . [testenv:black] extras = tests skipsdist = True -commands = black --check mail_editor docs tests +commands = black --check mail_editor tests [testenv:flake8] extras = tests skipsdist = True commands = flake8 . - -[testenv:docs] -basepython=python -changedir=docs -skipsdist=true -extras = - tests - docs -commands= - py.test check_sphinx.py -v \ - --tb=auto \ - {posargs} From 5e4d14bd98d354176ff71c181ba434ef9dd78af2 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Thu, 29 Feb 2024 09:40:54 +0100 Subject: [PATCH 9/9] Cleanup configuration, drop old setup.py --- _old_setup.py | 65 -------------------------------------------------- fix.sh | 1 - pyproject.toml | 5 ++++ setup.cfg | 17 ------------- 4 files changed, 5 insertions(+), 83 deletions(-) delete mode 100644 _old_setup.py diff --git a/_old_setup.py b/_old_setup.py deleted file mode 100644 index 1d58515..0000000 --- a/_old_setup.py +++ /dev/null @@ -1,65 +0,0 @@ -import os - -from setuptools import find_packages, setup - -# allow setup.py to be run from any path -os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) - -setup( - name='mail_editor', - version='0.3.5', - license='BSD', - - # packaging - install_requires=[ - 'Django>=1.8', - 'django-choices', - 'django-ckeditor', - 'requests', - 'lxml', - 'css_inline', - ], - include_package_data=True, - scripts=[], - packages=find_packages(exclude=["tests"]), - - # tests - setup_requires=['pytest-runner'], - tests_require=[ - 'factory-boy', - 'psycopg2', - 'pytest', - 'pytest-cov', - 'pytest-django', - 'pytest-pep8', - 'pytest-pylint', - 'pytest-pythonpath', - 'django-webtest', - ], - - # metadata - description='A Django package for email template editing', - url='https://github.com/maykinmedia/mail_editor', - author='Sergei Maertens, Maykin Media, Jorik Kraaikamp', - author_email='sergei@maykinmedia.nl', - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Environment :: Web Environment', - 'Framework :: Django', - 'Framework :: Django :: 1.8', - 'Framework :: Django :: 1.9', - 'Framework :: Django :: 1.10', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Topic :: Internet :: WWW/HTTP', - 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', - ], -) diff --git a/fix.sh b/fix.sh index 9e1d041..6499bcf 100755 --- a/fix.sh +++ b/fix.sh @@ -8,4 +8,3 @@ isort --profile black ./tests autoflake --in-place --remove-all-unused-imports -r ./tests black ./tests -black ./docs diff --git a/pyproject.toml b/pyproject.toml index b1a8e60..29da416 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,16 +14,21 @@ license = {file = "LICENSE"} keywords = ["TODO"] classifiers = [ "Development Status :: 3 - Alpha", + 'Environment :: Web Environment', "Framework :: Django", "Framework :: Django :: 3.2", "Framework :: Django :: 4.2", "Intended Audience :: Developers", + 'License :: OSI Approved :: BSD License', "Operating System :: Unix", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", + 'Programming Language :: Python', "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', "Topic :: Software Development :: Libraries :: Python Modules", ] requires-python = ">=3.10" diff --git a/setup.cfg b/setup.cfg index b4bb161..44f7e3b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,21 +14,4 @@ ignore=E203,E261,E501,E731,F405,W293,W291,W503,F841,E741 max-line-length=120 exclude=env,.tox -[isort] -combine_as_imports = true -default_section = THIRDPARTY -include_trailing_comma = false -line_length = 79 -multi_line_output = 5 -skip = env,node_modules -skip_glob = **/migrations/** -not_skip = __init__.py -known_django=django -known_first_party=mail_editor -sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER - -[tool:pytest] -django_find_project=false -DJANGO_SETTINGS_MODULE=tests.settings - python_paths=.