Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Django & package configuration from maykinmedia/default-app #48

Merged
merged 9 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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: ['3.2', '4.2']

name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }})

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: pip install tox tox-gh-actions

- name: Run tests
run: tox
env:
PYTHON_VERSION: ${{ matrix.python }}
DJANGO: ${{ matrix.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: ${{ secrets.PYPI_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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]
toxenv: [isort, black, flake8]
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: ${{ matrix.toxenv }}
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ include License
include README.rst
recursive-include mail_editor/templates *
recursive-include bin *
global-exclude __pycache__
global-exclude *.py[co]
35 changes: 13 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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': """
<h1>Hallo {{ name }},</h1>
Expand All @@ -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('/'),
}]
},
...
Expand Down
1 change: 1 addition & 0 deletions fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ black ./mail_editor
isort --profile black ./tests
autoflake --in-place --remove-all-unused-imports -r ./tests
black ./tests

9 changes: 4 additions & 5 deletions mail_editor/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
100 changes: 100 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[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 = "[email protected]"}
]
readme = "README.rst"
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"
dependencies = [
"django>=3.2",
"django-choices",
"django-ckeditor",
"requests",
"lxml",
"css_inline"
]

[project.urls]
Homepage = "https://github.com/maykinmedia/mail-editor"
Documentation = "https://github.com/maykinmedia/mail-editor"
"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",
"autoflake",
"django_webtest",
]
coverage = [
"pytest-cov",
]
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 = "tests.settings"

[tool.bumpversion]
current_version = "0.3.5"
files = [
{filename = "pyproject.toml"},
{filename = "README.rst"},
]

[tool.coverage.report]
exclude_also = [
"if (typing\\.)?TYPE_CHECKING:",
"@(typing\\.)?overload",
"class .*\\(.*Protocol.*\\):",
"@(abc\\.)?abstractmethod",
"raise NotImplementedError",
"\\.\\.\\.",
"pass",
]
22 changes: 4 additions & 18 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,12 @@ universal=1

[pep8]
ignore=W293,W291,E501,E261

max-line-length=120

exclude=migrations,static,media

[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
[flake8]
ignore=E203,E261,E501,E731,F405,W293,W291,W503,F841,E741
max-line-length=120
exclude=env,.tox

python_paths=.
Loading
Loading