Skip to content

Commit

Permalink
Merge pull request #4 from anfema/f.hoffmann/update-project-setup
Browse files Browse the repository at this point in the history
Update project setup & add django 4.2 support
  • Loading branch information
rollacting committed Dec 21, 2023
2 parents 9bf7c25 + e0df683 commit 14b3656
Show file tree
Hide file tree
Showing 35 changed files with 1,318 additions and 477 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ charset = utf-8

# Docstrings and comments use max_line_length = 79
[*.py]
max_line_length = 119
max_line_length = 120

[*.yml]
[*.{yml,yaml}]
indent_size = 2
24 changes: 24 additions & 0 deletions .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Code style checks
on:
pull_request:
branches: [ main, master ]
push:
branches: [ main, master ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff==0.1.7
# Update output format to enable automatic inline annotations.
- name: Run Ruff check
run: ruff check --output-format=github .
- name: Run Ruff format --check
run: ruff format --check --diff .
59 changes: 0 additions & 59 deletions .github/workflows/create_release.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/publish_release_on_pypi.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/publish_release_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
release:
types: [published]

name: Upload packages to PyPI and GitHub release on release publish
jobs:
upload-packages:
name: Create release-artifacts
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# required by ncipollo/release-action@v1
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install build dependencies
run: |
pipx install poetry
- name: Check package version (compare package version with tag)
run: |
if [[ ! "$(poetry version -s)" = "${{ github.event.release.tag_name}}" ]]; then
echo "version mismatch: $(poetry version -s) (package) vs ${{ github.event.release.tag_name }} (tag)"
exit 1
fi
- name: Build sdist & wheel
run: |
poetry build
- name: Update release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
artifacts: "dist/*"
- name: Publish python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# uses trusted publishing (no username & password required)
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.7
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/python-poetry/poetry
rev: 1.7.1
hooks:
- id: poetry-check
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Records mail delivery in the `SESMailDelivery` model and updates the state if a

## Requirements

- [Django](https://www.djangoproject.com) version 2.2+
- [Django](https://www.djangoproject.com) version 3.2+
- A [PostgreSQL](https://www.postgresql.org/) Database


Expand All @@ -25,14 +25,14 @@ Records mail delivery in the `SESMailDelivery` model and updates the state if a

3. [Setup](https://github.com/django-ses/django-ses#full-list-of-settings) `django-ses`

4. Add the webhook view to `urls.py` (use `SESSNSTrackerWebhookView` instead of `SESEventWebhookView` from `django_ses`):
4. Add the webhook view to `urls.py`:

```python
from ses_sns_tracker.views import SESSNSTrackerWebhookView
from django_ses.views import SESEventWebhookView

urlpatterns = [
# ...
path('ses-events/', SESSNSTrackerWebhookView.as_view(), name='handle-event-webhook'),
path('ses-events/', SESEventWebhookView.as_view(), name='handle-event-webhook'),
# ...
]
```
Expand All @@ -43,7 +43,7 @@ Records mail delivery in the `SESMailDelivery` model and updates the state if a
EMAIL_BACKEND = 'ses_sns_tracker.backends.SESSNSTrackerBackend'
```

This way all emails will be send via the Amazon SES API.
This way all emails will be sent via the Amazon SES API.

6. (Optional) Send an email via the `SESMailDelivery` manager (doesn't require `SESSNSTrackerBackend`
as the default mail backend):
Expand All @@ -70,24 +70,15 @@ Records mail delivery in the `SESMailDelivery` model and updates the state if a
will still be created).
*Default: `None`*

- `SES_SNS_TRACKER_USE_CRYPTOGRAPHY = True`

Use `crypthography` instead of `M2Crypto` to verify the signature of messages received from SNS.
*Default: `True`*


## Development setup

1. Upgrade packaging tools:
1. Install development dependencies:

```bash
pip install --upgrade pip setuptools wheel
poetry install
```

2. Install packages from `requirements-dev.txt`:

```bash
pip install -r requirements-dev.txt
```
2. Install the [ruff extension](https://docs.astral.sh/ruff/integrations/) for code linting & formatting in your IDE.

3. (Optional) Override settings in `example_proj/settings_local.py` & `tests/settings_local.py` as required.
72 changes: 36 additions & 36 deletions example_proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

import os
from contextlib import suppress


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -13,7 +15,7 @@
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4ysv*2#57v%8w!etrjxv=%kuugbc6wuth=^ih4$njj91to&ar+'
SECRET_KEY = "4ysv*2#57v%8w!etrjxv=%kuugbc6wuth=^ih4$njj91to&ar+"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -24,63 +26,63 @@
# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ses_sns_tracker',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"ses_sns_tracker",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'example_proj.urls'
ROOT_URLCONF = "example_proj.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'example_proj.wsgi.application'
WSGI_APPLICATION = "example_proj.wsgi.application"


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'ses_sns_tracker_dev',
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "ses_sns_tracker_dev",
}
}


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -92,9 +94,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = "/static/"

try:
from .settings_local import * # NOQA
except ImportError:
pass
with suppress(ImportError):
from .settings_local import * # noqa: F403
Loading

0 comments on commit 14b3656

Please sign in to comment.