Skip to content

Commit

Permalink
feat: py 3.10, django4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme committed Dec 21, 2021
1 parent e5f0da4 commit cd96129
Show file tree
Hide file tree
Showing 31 changed files with 400 additions and 313 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: [3.6, 3.7, 3.8, 3.9]
python: [3.6, 3.7, 3.8, 3.9, '3.10']
django:
- 'django>=4.0.0, <4.1'
- 'django>=3.2.0, <3.3'
- 'django>=3.1.0, <3.2'
- 'django>=3.0.0, <3.1'
- 'django>=2.2.0, <3.0'
- 'django>=2.1.0, <2.2.0'
- 'django>=2.0.0, <2.1.0'
exclude:
- python: 3.6
django: 'django>=4.0.0, <4.1'
- python: 3.7
django: 'django>=4.0.0, <4.1'
- python: "3.10"
django: 'django>=2.0.0, <2.1.0'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand All @@ -33,12 +42,11 @@ jobs:
pip install ".[test, ci]"
pip install "${{ matrix.django }}" --upgrade
# ignore for now
# - name: Lint with ${{ matrix.python }}
# if: ${{ matrix.python == '3.8' }}
# run: make lint
- name: Lint with ${{ matrix.python }}
if: ${{ matrix.python == '3.8' }}
run: make lint

- name: Install, test and code coverage with ${{ matrix.python }}
run: |
python setup.py install
make test
env:
PYTHONPATH: ${{ github.workspace }}
run: make test
32 changes: 32 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: reviewdog
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
reviewdog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest

- uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Add pip bin to PATH
run: echo "/home/runner/.local/bin" >> $GITHUB_PATH

- name: Install deps
run: pip install ".[ci]"

- name: Reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make reviewdog
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.python-version

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -47,12 +48,15 @@ coverage.xml

# Django stuff:
*.log
simple_test_db

# Sphinx documentation
docs/_build/

# PyBuilder
target/

.vscode
.DS_Store
/.eggs/
.envrc
env
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2021 Stream.io Inc, and individual contributors.
Copyright (c) 2014-2022 Stream.io Inc, and individual contributors.

All rights reserved.

Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ help: ## Display this help message
{printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'

lint: ## Run linters
black --check stream
flake8 --ignore=E501,E225,W293,W503,F401 stream_django
black --check stream_django
flake8 --ignore=E501,E203,W503 stream_django

lint-fix:
black stream_django

test: ## Run tests
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) python setup.py test
STREAM_API_KEY=$(STREAM_KEY) \
STREAM_API_SECRET=$(STREAM_SECRET) \
DJANGO_SETTINGS_MODULE=stream_django.tests.test_app.settings \
pytest stream_django/tests

check: lint test ## Run linters + tests

reviewdog:
black --check --diff --quiet stream_django | reviewdog -f=diff -f.diff.strip=0 -filter-mode="diff_context" -name=black -reporter=github-pr-review
flake8 --ignore=E501,E203,W503 stream_django | reviewdog -f=flake8 -name=flake8 -reporter=github-pr-review
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Stream Django
[![build](https://github.com/GetStream/stream-django/workflows/build/badge.svg)](https://github.com/GetStream/stream-django/actions) [![PyPI version](https://badge.fury.io/py/stream-django.svg)](http://badge.fury.io/py/stream-django)

[stream-django](https://github.com/GetStream/stream-django) is a Django client for [Stream](https://getstream.io/), it supports Django from 1.11 up to and including 3.2 using Python 2.7 and 3.4, 3.5, 3.6+.
[stream-django](https://github.com/GetStream/stream-django) is a Django client for [Stream](https://getstream.io/), it supports Django from 1.11 up to and including 4.0 using Python 2.7 and 3.4, 3.5, 3.6+.

You can sign up for a Stream account at https://getstream.io/get_started.

Expand Down Expand Up @@ -371,6 +371,6 @@ special_feed.follow('timeline:60')

### Copyright and License Information

Copyright (c) 2014-2021 Stream.io Inc, and individual contributors. All rights reserved.
Copyright (c) 2014-2022 Stream.io Inc, and individual contributors. All rights reserved.

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.
26 changes: 0 additions & 26 deletions runtests.py

This file was deleted.

23 changes: 17 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@
if sys.version_info < (3, 0, 0):
django = "django>=1.11.29,<2.0"
else:
django = "django>=2.0,<3.3" # checked https://docs.djangoproject.com/en/dev/releases/3.2/#backwards-incompatible-3-2
django = "django>=2.0,<5.0"

requirements = [django, "stream-python>=3.0.1", "pytz"]

extras_require = {"test": ["httpretty==1.1.1"], "ci": ["black", "flake8", "pytest-cov"]}
extras_require = {
"test": ["httpretty"],
"ci": ["black; python_version > '3.6'", "flake8", "pytest-cov", "pytest-django"],
}

version = "1.7.1"

setup(
name="stream-django",
version="1.7.1",
version=version,
url="https://github.com/GetStream/stream-django",
project_urls={
"Bug Tracker": "https://github.com/GetStream/stream-django/issues",
"Documentation": "https://getstream.io/activity-feeds/docs/python/adding_activities/?language=python",
"Release Notes": "https://github.com/GetStream/stream-django/releases/tag/{}".format(
version
),
},
packages=["stream_django"],
include_package_data=True,
install_requires=requirements,
extras_require=extras_require,
tests_require=["stream_django[test]"],
test_suite="runtests.runtests",
license="BSD License",
description="A Django app to build activity, news and notification feeds.",
long_description_content_type="text/markdown",
long_description=README,
url="https://getstream.io/",
author="Tommaso Barbugli",
author_email="tbarbugli@gmail.com",
classifiers=[
Expand All @@ -44,6 +54,7 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
],
Expand Down
4 changes: 2 additions & 2 deletions stream_django/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import django
from stream_django.feed_manager import feed_manager # noqa

version_list = [int(i) for i in django.__version__.split('.')]
version_list = [int(i) for i in django.__version__.split(".")]
major, minor = version_list[0], version_list[1]

if major < 3 or (major == 3 and minor < 2):
# deprecated as of Django 3.2
default_app_config = 'stream_django.apps.StreamDjangoConfig'
default_app_config = "stream_django.apps.StreamDjangoConfig"
43 changes: 21 additions & 22 deletions stream_django/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,73 @@


def model_content_type(cls):
return '%s.%s' % (cls._meta.app_label, cls._meta.object_name)
return "%s.%s" % (cls._meta.app_label, cls._meta.object_name)


def create_reference(reference):
if isinstance(reference, (models.Model, )):
if isinstance(reference, (models.Model,)):
return create_model_reference(reference)
return reference


def create_model_reference(model_instance):
'''
"""
creates a reference to a model instance that can be stored in activities
>>> from core.models import Like
>>> like = Like.object.get(id=1)
>>> create_reference(like)
core.Like:1
'''
"""
content_type = model_content_type(model_instance.__class__)
content_id = model_instance.pk
return '%s:%s' % (content_type, content_id)
return "%s:%s" % (content_type, content_id)


class Activity(object):

@property
def activity_author_feed(self):
'''
"""
The name of the feed where the activity will be stored; this is normally
used by the manager class to determine if the activity should be stored elsewhere than
settings.USER_FEED
'''
"""
pass

@classmethod
def activity_related_models(cls):
'''
"""
Use this hook to setup related models to load during enrichment.
It must return None or a list of relationships see Django select_related for reference
'''
"""
pass

@property
def extra_activity_data(self):
'''
"""
Use this hook to store extra data in activities.
If you need to store references to model instances you should use create_model_reference
eg:
@property
def activity_extra_activity_data(self):
dict('parent_user'=create_reference(self.parent_user))
'''
"""
pass

@property
def activity_actor_attr(self):
'''
"""
Returns the model instance field that references the activity actor
'''
"""
return self.user

@property
def activity_object_attr(self):
'''
"""
Returns the reference to the object of the activity
'''
"""
return self

@property
Expand All @@ -88,7 +87,7 @@ def activity_actor(self):
def activity_verb(self):
model_name = slugify(self.__class__.__name__)
return model_name

@property
def activity_object(self):
return create_reference(self.activity_object_attr)
Expand All @@ -103,20 +102,20 @@ def activity_time(self):
if is_aware(self.created_at):
atime = make_naive(atime, pytz.utc)
return atime

@property
def activity_notify(self):
pass

def create_activity(self):
extra_data = self.extra_activity_data
if not extra_data:
extra_data = {}

to = self.activity_notify
if to:
extra_data['to'] = [f.id for f in to]
extra_data["to"] = [f.id for f in to]

activity = dict(
actor=self.activity_actor,
verb=self.activity_verb,
Expand Down
9 changes: 6 additions & 3 deletions stream_django/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from django.core.exceptions import ImproperlyConfigured
from stream_django.conf import is_valid_config


class StreamDjangoConfig(AppConfig):
name = 'stream_django'
name = "stream_django"
verbose_name = "Stream Django"

def ready(self):
if not is_valid_config():
raise ImproperlyConfigured('Stream credentials are not set in your settings')
if not is_valid_config():
raise ImproperlyConfigured(
"Stream credentials are not set in your settings"
)
Loading

0 comments on commit cd96129

Please sign in to comment.