Skip to content

Commit

Permalink
move build env to github actions, use django-jsonfield-backport
Browse files Browse the repository at this point in the history
  • Loading branch information
lociii authored and auvipy committed Jan 13, 2021
1 parent 04db1ed commit 98ab80b
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 121 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Test and deploy

# define when to run the action
on:
- push
- pull_request

env:
GITHUB_WORKFLOW: true

jobs:
test:
name: Test
runs-on: ubuntu-20.04

# test matrix
strategy:
fail-fast: false
matrix:
python-version:
- 3.6
- 3.7
- 3.8
- 3.9
django:
- 2.2
- 3.0
- 3.1
database:
- sqlite
- mysql
- postgres

# additional service containers to run
services:
# postgres service
postgres:
# docker hub image
image: postgres:9.5-alpine
# configure the instance
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
# set health checks to wait until service has started
options: >-
--health-cmd="pg_isready"
--health-interval=10s
--health-timeout=5s
--health-retries=5
# mysql service
mysql:
# docker hub image
image: mysql:5.7
# configure the instance
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: test
ports:
- 3306:3306
# set health checks to wait until service has started
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
# check out revision to test
- uses: actions/checkout@v2

# install python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

# upgrade pip
- name: Update pip
run: python -m pip install --upgrade pip

# install environment specific dependencies
- name: Install coverage
run: pip install coverage>=5.3
- name: Install Django 2.2
if: matrix.django == 2.2
run: pip install "Django>=2.2,<3.0"
- name: Install Django 3.0
if: matrix.django == 3.0
run: pip install "Django>=3.0,<3.1"
- name: Install Django 3.1
if: matrix.django == 3.1
run: pip install "Django>=3.1,<3.2"
- name: Install MySQL libs
if: matrix.database == 'mysql'
run: pip install mysqlclient>=2.0.1 django-mysql>=3.9.0
- name: Install postgres libs
if: matrix.database == 'postgres'
run: pip install psycopg2>=2.8.6
- name: Install django-jsonfield-backport
if: matrix.django == 2.2 || matrix.django == 3.0
run: pip install "django-jsonfield-backport>=1.0.2,<2.0"

# install our package
- name: Install package
run: pip install -e .

# execute the tests
- name: Run tests
run: coverage run runtests/manage.py test -v3 --noinput actstream testapp testapp_nested
env:
DATABASE_ENGINE: ${{ matrix.database }}
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

30 changes: 23 additions & 7 deletions actstream/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from collections import OrderedDict

import django
from django.apps import apps
from django.apps import AppConfig
from django.conf import settings

from actstream import settings
from actstream import settings as actstream_settings
from actstream.signals import action


Expand All @@ -12,9 +17,20 @@ def ready(self):
action.connect(action_handler, dispatch_uid='actstream.models')
action_class = self.get_model('action')

if settings.USE_JSONFIELD and not hasattr(action_class, 'data'):
from actstream.jsonfield import DataField, register_app
DataField(blank=True, null=True).contribute_to_class(
action_class, 'data'
)
register_app(self)
if actstream_settings.USE_JSONFIELD:
if not hasattr(action_class, 'data'):
from actstream.jsonfield import DataField
DataField(blank=True, null=True).contribute_to_class(
action_class, 'data'
)

# dynamically load django_jsonfield_backport to INSTALLED_APPS
if django.VERSION < (3, 1) and 'django_jsonfield_backport' not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS += ('django_jsonfield_backport', )
# reset loaded apps
apps.app_configs = OrderedDict()
# reset initialization status
apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False
apps.clear_cache()
# re-initialize all apps
apps.populate(settings.INSTALLED_APPS)
24 changes: 9 additions & 15 deletions actstream/jsonfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,29 @@
afterwards.
'''
import django
from django.db import models
from django.core.exceptions import ImproperlyConfigured

from actstream.settings import USE_JSONFIELD


__all__ = ('DataField', 'register_app')


def register_app(app):
"""Noop unless django-jsonfield-compat overwrites it."""
pass
__all__ = ('DataField', )


DataField = models.TextField

if USE_JSONFIELD:
try:
from jsonfield_compat import JSONField, register_app
if django.VERSION >= (3, 1):
from django.db.models import JSONField
DataField = JSONField
except ImportError as err:
else:
try:
from django_mysql.models import JSONField
from django_jsonfield_backport.models import JSONField
DataField = JSONField

except ImportError:
raise ImproperlyConfigured(
'You must either install django-jsonfield + '
'django-jsonfield-compat, or django-mysql as an '
'alternative, if you wish to use a JSONField on your '
'actions'
'You must install django-jsonfield-backport, '
'if you wish to use a JSONField on your actions '
'and run Django < 3.1'
)
4 changes: 1 addition & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Django>=1.11
Sphinx
git+https://github.com/justquick/alabaster.git#egg=alabaster
django-jsonfield>=1.0.1
django-jsonfield-compat>=0.4.4

django-jsonfield-backport>=1.0.2
6 changes: 6 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Changelog
=========

Unreleased
----------
- Replace travis by GitHub actions for CI
- BREAKING: Replace JSONField libs with django-jsonfield-backport


0.9.0
-----
- Support django 3.0
Expand Down
10 changes: 4 additions & 6 deletions docs/source/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ Adding Custom Data to your Actions
As of v0.4.4, django-activity-stream now supports adding custom data to any Actions you generate.
This uses a ``data`` JSONField on every Action where you can insert and delete values at will.
This behavior is disabled by default but just set ``ACTSTREAM_SETTINGS['USE_JSONFIELD'] = True`` in your
settings.py to enable it. If you're running Django >= 1.9 and you'd like to use the JSONField included
with Django, set ``USE_NATIVE_JSONFIELD = True`` in your settings file.
settings.py to enable it.

.. note::

Multiple implementations of the JSONField are supported, depending on which packages are installed:
If you're running Django < 3.1 you must install django-jsonfield-backport or the extra ``jsonfield`` of this package.
"django_jsonfield_backport" gets dynamically added to the INSTALLED_APPS of your Django application if not yet done manually.

- The default and preferred implementation is used by installing **both** `django-jsonfield <https://bitbucket.org/schinckel/django-jsonfield/>`_ and `django-jsonfield-compat <https://github.com/kbussell/django-jsonfield-compat>`_. This is also allowing to use Django's native JSONField as described above.

- Alternatively you can install **only** `django-mysql <https://github.com/adamchainz/django-mysql>`_ (*requires MySQL 5.7+*) to use its JSONField. Make sure the packages above are **not installed**, as they would be preferred. This can be useful when you are using django-mysql already and want to use the same field for actstream.
Please make sure to remove both the django-jsonfield-backport package and the ``django_jsonfield_backport`` INSTALLED_APPS entry (if manually added) after upgrading to Django >= 3.1

You can send the custom data as extra keyword arguments to the ``action`` signal.

Expand Down
5 changes: 3 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ The activity urls are not required for basic usage but provide activity :ref:`fe
Add extra data to actions
-------------------------

If you want to use custom data on your actions, then make sure you have `django-jsonfield <https://pypi.org/project/django-jsonfield/>`_ installed
If you want to use custom data on your actions and are running Django < 3.1, then make sure you have
`django-jsonfield-backport <https://pypi.org/project/django-jsonfield-backport/>`_ installed.

.. code-block:: bash
Expand All @@ -74,7 +75,7 @@ Python
******


* **Python 3**: 3.5 to 3.8
* **Python 3**: 3.6 to 3.9
* **PyPy**: 3

Django
Expand Down
3 changes: 1 addition & 2 deletions runtests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Django>=2.2.17
django-jsonfield
django-jsonfield-compat
django-jsonfield-backport
tblib
49 changes: 32 additions & 17 deletions runtests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,46 @@
('Justin Quick', 'justquick@gmail.com'),
)

ENGINE = os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3')
DATABASES = {
'default': {
'ENGINE': ENGINE,
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
'OPTIONS': {
}
}
}

if 'postgres' in ENGINE or 'mysql' in ENGINE:
USER, PASSWORD = 'test', 'test'
if os.environ.get('TRAVIS', False):
if 'mysql' in ENGINE:
USER, PASSWORD = 'travis', ''
else:
USER, PASSWORD = 'postgres', ''
DATABASES['default'].update(
NAME='test',
USER=os.environ.get('DATABASE_USER', USER),
PASSWORD=os.environ.get('DATABASE_PASSWORD', PASSWORD),
HOST=os.environ.get('DATABASE_HOST', 'localhost')
)

print(DATABASES)
if os.environ.get('GITHUB_WORKFLOW', False):
DATABASE_ENGINE = os.environ.get('DATABASE_ENGINE', 'sqlite')
if 'mysql' in DATABASE_ENGINE:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '3306',
},
}
elif 'postgres' in DATABASE_ENGINE:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': '127.0.0.1',
'PORT': '5432',
},
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
},
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
'Programming Language :: Python :: 3',
'Topic :: Utilities'],
extras_require={
'jsonfield': ['django-jsonfield>=1.0.1',
'django-jsonfield-compat>=0.4.4'],
'jsonfield': ['django-jsonfield-backport>=1.0.2,<2.0'],
},
)
Loading

0 comments on commit 98ab80b

Please sign in to comment.