Skip to content

Commit

Permalink
py3.9対応+次バージョン 0.48 用の記述をsetup.pyに追加 (#14)
Browse files Browse the repository at this point in the history
* py36-django22を通すための改修を反映。py 2.7とdjango1.11のテストを削除。

* celery 4.2系, celery5.1系を指定する記述を追加

* py39のテストシナリオを追加

* Django 3系の条件を追記。対応はまだ。

* wip: py39-django32でfailする

* django3.2のtoxがpassするように調整

* コメントを追加

* travis-ciの設定を削除。GitHub Actionsの設定を追加。

* tox.iniにtox-gh-actionsの設定を追加

* コメントを追加。github-actionsのmatrix条件を追加。

* py3.9のテストが起動しなくなったので、matrixの条件を減らす意図で、celeryの条件を削除

* strategy.max-parallelを指定。tox.iniに[gh-actions:env]の項目を追加。matrixにceleryの条件を追加。

* max-paraallelの記述を削除。toxのオプションを削除。

* 記述が難しくなったので、test.ymlの記述をいったん簡略化。

* gh-actions関連の修正

* gh-actions関連の修正

* gh-actions関連の修正

* gh-actions設定の調整

* gh-actions設定の調整

* コメントを修正

* setup.pyの記述をtox.iniの情報に合うように変更。バージョンを0.48に変更。リンク参照先とリンク先を異なるものにしたいため、READMEをrst形式の記述に変更。

* READMEをmd形式からrst形式に変更するにあたってに影響する箇所を修正。PyPIに掲載する情報を他のbp管理パッケージに合わせて追加。

* setup.pyのinstall_requires: 'django-jsonfield>=1.0.1' は記述を省けなかったので元に戻す。記述理由のコメントを追加。

* readmeの依存パッケージの記述を修正

* コメント文を修正

* suggestionを反映

Co-authored-by: Takayuki SHIMIZUKAWA <[email protected]>

* メソッド名変更に伴いテストコードも調整

* mockは標準ライブラリ unittestのmockを使うように変更

* ChageLogを追加

* 変更点を追記

* manifest.inにchageLogを追加

* change logを修正しました。
mockパッケージの件は、bpnotifyパッケージ内部の話なので、Featuresに変更しました。
サポート終了の話題を、Imcompatible Changesの欄に移動しました。
Celeryのメソッド名という表現をタスク名に変更しました(さらに、メソッド名ではなく、関数名だった)

Co-authored-by: Takayuki SHIMIZUKAWA <[email protected]>
  • Loading branch information
imaxyz and shimizukawa authored Apr 11, 2022
1 parent 1e8efd6 commit 4c7694e
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 132 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests

# push と pull request イベント毎にGtihubのWorkflowを起動する
on:
- push
- pull_request

jobs:
# ジョブの名称
test_with_tox:
name: build (Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }})
runs-on: ubuntu-latest

# 並列して実行する各ジョブのPythonバージョン
strategy:
matrix:
python-version: ['3.6', '3.9']
django-version: ['2.2', '3.2']

steps:
# ソースコードをチェックアウト
- uses: actions/checkout@v2

# ジョブのPython環境を設定
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

# Github Actionsからtoxを実行するために必要なパッケージをインストール
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
# Github Actionsからtoxを実行
- name: Test with tox
run: |
tox -v
env:
DJANGO: ${{ matrix.django-version }}
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

19 changes: 19 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ChangeLog
=========

0.48 (2022-04-11)
===================

Features:


- Python3.9のサポートを追加しました。
- toxの実行環境を、Travis CIからGitHubに変更しました。
- READMEの書式をmarkdownからreStructuredTxtに変更しました。 
- mockパッケージに関して、標準ライブラリのunitestに含まれるmockを使用するように変更しました。

Incompatible Changes:

- Python2.7のサポートを終了しました。
- Django1.11のサポートを終了しました。
- Celeryのタスク名を `Notify` から `notify` に変更しました。
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
recursive-include beproud/django/notify/tests/templates *
recursive-include beproud/django/notify/templates *
recursive-include beproud/django/notify/fixtures *
include README.md
include README.rst
include CHANGES.rst
11 changes: 0 additions & 11 deletions README.md

This file was deleted.

20 changes: 20 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. image:: https://github.com/beproud/bpnotify/actions/workflows/tests.yml/badge.svg
:target: https://github.com/beproud/bpnotify/actions
:alt: GitHub Actions

`bpnotify` is notification routing for Django. Application notify function with targets, notify_type, media, extra_data, then bpnotify send notify with backend (example: mail).

Requirements
============

* Python (3.6, 3.9)
* Celery (4.2, 5.1, 5.2)
* Django (2.2, 3.2)
* six
* django-jsonfield (1.0.1)

Links
=================

* `release checklist <https://github.com/beproud/bpnotify/blob/master/release_checklist.rst>`_

51 changes: 17 additions & 34 deletions beproud/django/notify/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,24 @@
from django.conf import settings

import celery
from celery.task import Task
from celery.registry import tasks

if celery.VERSION < (3, 1):
try:
import djcelery # NOQA
except ImportError:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("when used celery<3.1, djcelery is required!")

if 'djcelery' not in settings.INSTALLED_APPS:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("djcelery not in INSTALLED_APPS!")
from celery import shared_task

from beproud.django.notify import notify_now


class Notify(Task):

def run(self, targets, notify_type, extra_data={}, include_media=None, exclude_media=[],
@shared_task(bind=True)
def notify(self, targets, notify_type, extra_data={}, include_media=None, exclude_media=[],
max_retries=3, retry_countdown=10, **kwargs):
try:
return notify_now(
targets,
notify_type,
extra_data=extra_data,
include_media=include_media,
exclude_media=exclude_media,
)
except Exception as e:
return self.retry(
exc=e,
countdown=retry_countdown,
max_retries=max_retries,
)


tasks.register(Notify)
try:
return notify_now(
targets,
notify_type,
extra_data=extra_data,
include_media=include_media,
exclude_media=exclude_media,
)
except Exception as e:
return self.retry(
exc=e,
countdown=retry_countdown,
max_retries=max_retries,
)
8 changes: 4 additions & 4 deletions beproud/django/notify/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#:coding=utf8:

import mock
from unittest import mock

from django.test import TestCase
from django.contrib.auth.models import User
Expand Down Expand Up @@ -40,7 +40,7 @@ def test_notify_task(self):
Simple task to test the Notify task.
"""
user = User.objects.get(pk=2)
notify_tasks.Notify.delay(
notify_tasks.notify.delay(
targets=[user],
notify_type='private_msg',
)
Expand All @@ -67,7 +67,7 @@ def _notify_now(*args, **kwargs):
notify_now.side_effect = _notify_now

user = User.objects.get(pk=2)
notify_tasks.Notify.delay(
notify_tasks.notify.delay(
targets=[user],
notify_type='private_msg',
)
Expand All @@ -92,7 +92,7 @@ def _notify_now(*args, **kwargs):
notify_now.side_effect = _notify_now

user = User.objects.get(pk=2)
notify_tasks.Notify.delay(
notify_tasks.notify.delay(
targets=[user],
notify_type='private_msg',
)
Expand Down
37 changes: 37 additions & 0 deletions release_checklist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
リリース手順
==============

事前準備
--------------

* GitHub, PyPI, TestPyPIのアカウントにbpnotifyの編集権限を設定
* パッケージのビルドに使用するパッケージをインストール

* ``pip install wheel twine``


手順
--------------------
1. 次バージョンのパッケージをビルド

* ``python setup.py sdist bdist_wheel``

2. twineのコマンドを実行して、エラーが出ないことを確認

* ``twine check --strict dist/*``

3. dist/に作成したパッケージをTestPyPIへアップロード

* ``twine upload --repository testpypi dist/*``

4. TestPyPIで、descriptionがエラーなく表示されていることと、ビルドしたパッケージがアップロードされていることを確認

* TestPyPIへアップロードした内容に問題がある場合、修正したパッケージをTestPyPIに再度アップロード

5. GitHubで次バージョンのReleaseタグを作成し、Publish Releaseを実行

* dist/に試行錯誤したパッケージが残っている場合、一度全て削除し、本番アップロード用のパッケージを再度作成

6. dist/に作成したパッケージを本番環境のPyPIにアップロード

* ``twine upload dist/*``
16 changes: 12 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,37 @@ def read_file(filename):

setup(
name='bpnotify',
version='0.47',
version='0.48',
description='Notification routing for Django',
author='BeProud',
author_email='[email protected]',
long_description=read_file('README.md'),
long_description_content_type="text/markdown",
long_description=read_file('README.rst'),
long_description_content_type="text/x-rst",
url='https://github.com/beproud/bpnotify/',
python_requires='>=3.6',
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Plugins',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.9',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.2',
'Topic :: Software Development :: Libraries :: Python Modules',
],
include_package_data=True,
packages=find_packages(),
namespace_packages=['beproud', 'beproud.django'],
test_suite='tests.main',
install_requires=[
'Django>=1.11',
'Django>=2.2',
'django-jsonfield>=1.0.1',
'Celery>=4.2',
'six',
],
zip_safe=False,
Expand Down
60 changes: 60 additions & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Django3では、標準のdjango.conf.global_settingsの定数をオーバーライドすると例外が発生する場合がある。
# https://github.com/django/django/blob/70035fb0444ae7c01613374212ca5e3c27c9782c/django/conf/__init__.py#L188
# そのため、testではdjango.conf.global_settingsを直接利用せず、このtest用settings定数を使用する。

SECRET_KEY = "SECRET"
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'beproud.django.notify',
)

# kombu.exceptions.EncodeError: Object of type User is not JSON serializable エラーを抑止する
# (参考)
# https://github.com/celery/celery/issues/5922
# https://stackoverflow.com/questions/49373825/kombu-exceptions-encodeerror-user-is-not-json-serializable
CELERY_TASK_SERIALIZER = "pickle"

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

import os
BASE_PATH = os.path.dirname(__file__)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_PATH, 'beproud', 'django', 'notify', 'tests', 'templates')
],
},
]

CELERY_TASK_ALWAYS_EAGER = True

BPNOTIFY_MEDIA = {
"news": {
"verbose_name": "News",
"default_types": ("new_user", "follow", "private_msg"),
"backends": (
"beproud.django.notify.backends.model.ModelBackend",
),
},
"private_messages": {
"verbose_name": "Private Message",
"default_types": ("private_msg", "notify_type_with_length_over_thirty"),
"backends": (
"beproud.django.notify.backends.model.ModelBackend",
"beproud.django.notify.backends.mail.EmailBackend",
),
},
}
BPNOTIFY_SETTINGS_STORAGE = 'beproud.django.notify.storage.db.DBStorage'

# The name of the class to use to run the test suite
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

Loading

0 comments on commit 4c7694e

Please sign in to comment.