Skip to content

Commit cd96129

Browse files
authored
feat: py 3.10, django4 support
1 parent e5f0da4 commit cd96129

31 files changed

+400
-313
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
strategy:
12+
fail-fast: false
1213
matrix:
13-
python: [3.6, 3.7, 3.8, 3.9]
14+
python: [3.6, 3.7, 3.8, 3.9, '3.10']
1415
django:
16+
- 'django>=4.0.0, <4.1'
1517
- 'django>=3.2.0, <3.3'
1618
- 'django>=3.1.0, <3.2'
1719
- 'django>=3.0.0, <3.1'
1820
- 'django>=2.2.0, <3.0'
1921
- 'django>=2.1.0, <2.2.0'
2022
- 'django>=2.0.0, <2.1.0'
23+
exclude:
24+
- python: 3.6
25+
django: 'django>=4.0.0, <4.1'
26+
- python: 3.7
27+
django: 'django>=4.0.0, <4.1'
28+
- python: "3.10"
29+
django: 'django>=2.0.0, <2.1.0'
2130
steps:
2231
- uses: actions/checkout@v2
2332
- uses: actions/setup-python@v2
@@ -33,12 +42,11 @@ jobs:
3342
pip install ".[test, ci]"
3443
pip install "${{ matrix.django }}" --upgrade
3544
36-
# ignore for now
37-
# - name: Lint with ${{ matrix.python }}
38-
# if: ${{ matrix.python == '3.8' }}
39-
# run: make lint
45+
- name: Lint with ${{ matrix.python }}
46+
if: ${{ matrix.python == '3.8' }}
47+
run: make lint
4048

4149
- name: Install, test and code coverage with ${{ matrix.python }}
42-
run: |
43-
python setup.py install
44-
make test
50+
env:
51+
PYTHONPATH: ${{ github.workspace }}
52+
run: make test

.github/workflows/reviewdog.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: reviewdog
2+
on:
3+
pull_request:
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.head_ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
reviewdog:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- uses: reviewdog/action-setup@v1
16+
with:
17+
reviewdog_version: latest
18+
19+
- uses: actions/setup-python@v2
20+
with:
21+
python-version: "3.10"
22+
23+
- name: Add pip bin to PATH
24+
run: echo "/home/runner/.local/bin" >> $GITHUB_PATH
25+
26+
- name: Install deps
27+
run: pip install ".[ci]"
28+
29+
- name: Reviewdog
30+
env:
31+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: make reviewdog

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var/
2222
*.egg-info/
2323
.installed.cfg
2424
*.egg
25+
.python-version
2526

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

4849
# Django stuff:
4950
*.log
51+
simple_test_db
5052

5153
# Sphinx documentation
5254
docs/_build/
5355

5456
# PyBuilder
5557
target/
56-
58+
.vscode
5759
.DS_Store
5860
/.eggs/
61+
.envrc
62+
env

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014-2021 Stream.io Inc, and individual contributors.
1+
Copyright (c) 2014-2022 Stream.io Inc, and individual contributors.
22

33
All rights reserved.
44

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ help: ## Display this help message
99
{printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'
1010

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

1515
lint-fix:
1616
black stream_django
1717

1818
test: ## Run tests
19-
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) python setup.py test
19+
STREAM_API_KEY=$(STREAM_KEY) \
20+
STREAM_API_SECRET=$(STREAM_SECRET) \
21+
DJANGO_SETTINGS_MODULE=stream_django.tests.test_app.settings \
22+
pytest stream_django/tests
2023

2124
check: lint test ## Run linters + tests
25+
26+
reviewdog:
27+
black --check --diff --quiet stream_django | reviewdog -f=diff -f.diff.strip=0 -filter-mode="diff_context" -name=black -reporter=github-pr-review
28+
flake8 --ignore=E501,E203,W503 stream_django | reviewdog -f=flake8 -name=flake8 -reporter=github-pr-review

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Stream Django
22
[![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)
33

4-
[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+.
4+
[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+.
55

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

@@ -371,6 +371,6 @@ special_feed.follow('timeline:60')
371371

372372
### Copyright and License Information
373373

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

376376
See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

runtests.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

setup.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,36 @@
99
if sys.version_info < (3, 0, 0):
1010
django = "django>=1.11.29,<2.0"
1111
else:
12-
django = "django>=2.0,<3.3" # checked https://docs.djangoproject.com/en/dev/releases/3.2/#backwards-incompatible-3-2
12+
django = "django>=2.0,<5.0"
1313

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

16-
extras_require = {"test": ["httpretty==1.1.1"], "ci": ["black", "flake8", "pytest-cov"]}
16+
extras_require = {
17+
"test": ["httpretty"],
18+
"ci": ["black; python_version > '3.6'", "flake8", "pytest-cov", "pytest-django"],
19+
}
20+
21+
version = "1.7.1"
1722

1823
setup(
1924
name="stream-django",
20-
version="1.7.1",
25+
version=version,
26+
url="https://github.com/GetStream/stream-django",
27+
project_urls={
28+
"Bug Tracker": "https://github.com/GetStream/stream-django/issues",
29+
"Documentation": "https://getstream.io/activity-feeds/docs/python/adding_activities/?language=python",
30+
"Release Notes": "https://github.com/GetStream/stream-django/releases/tag/{}".format(
31+
version
32+
),
33+
},
2134
packages=["stream_django"],
2235
include_package_data=True,
2336
install_requires=requirements,
2437
extras_require=extras_require,
25-
tests_require=["stream_django[test]"],
26-
test_suite="runtests.runtests",
2738
license="BSD License",
2839
description="A Django app to build activity, news and notification feeds.",
2940
long_description_content_type="text/markdown",
3041
long_description=README,
31-
url="https://getstream.io/",
3242
author="Tommaso Barbugli",
3343
author_email="[email protected]",
3444
classifiers=[
@@ -44,6 +54,7 @@
4454
"Programming Language :: Python :: 3.7",
4555
"Programming Language :: Python :: 3.8",
4656
"Programming Language :: Python :: 3.9",
57+
"Programming Language :: Python :: 3.10",
4758
"Topic :: Internet :: WWW/HTTP",
4859
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
4960
],

stream_django/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import django
22
from stream_django.feed_manager import feed_manager # noqa
33

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

77
if major < 3 or (major == 3 and minor < 2):
88
# deprecated as of Django 3.2
9-
default_app_config = 'stream_django.apps.StreamDjangoConfig'
9+
default_app_config = "stream_django.apps.StreamDjangoConfig"

stream_django/activity.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,73 @@
66

77

88
def model_content_type(cls):
9-
return '%s.%s' % (cls._meta.app_label, cls._meta.object_name)
9+
return "%s.%s" % (cls._meta.app_label, cls._meta.object_name)
1010

1111

1212
def create_reference(reference):
13-
if isinstance(reference, (models.Model, )):
13+
if isinstance(reference, (models.Model,)):
1414
return create_model_reference(reference)
1515
return reference
1616

1717

1818
def create_model_reference(model_instance):
19-
'''
19+
"""
2020
creates a reference to a model instance that can be stored in activities
2121
2222
>>> from core.models import Like
2323
>>> like = Like.object.get(id=1)
2424
>>> create_reference(like)
2525
core.Like:1
2626
27-
'''
27+
"""
2828
content_type = model_content_type(model_instance.__class__)
2929
content_id = model_instance.pk
30-
return '%s:%s' % (content_type, content_id)
30+
return "%s:%s" % (content_type, content_id)
3131

3232

3333
class Activity(object):
34-
3534
@property
3635
def activity_author_feed(self):
37-
'''
36+
"""
3837
The name of the feed where the activity will be stored; this is normally
3938
used by the manager class to determine if the activity should be stored elsewhere than
4039
settings.USER_FEED
41-
'''
40+
"""
4241
pass
4342

4443
@classmethod
4544
def activity_related_models(cls):
46-
'''
45+
"""
4746
Use this hook to setup related models to load during enrichment.
4847
It must return None or a list of relationships see Django select_related for reference
49-
'''
48+
"""
5049
pass
5150

5251
@property
5352
def extra_activity_data(self):
54-
'''
53+
"""
5554
Use this hook to store extra data in activities.
5655
If you need to store references to model instances you should use create_model_reference
5756
5857
eg:
5958
@property
6059
def activity_extra_activity_data(self):
6160
dict('parent_user'=create_reference(self.parent_user))
62-
'''
61+
"""
6362
pass
6463

6564
@property
6665
def activity_actor_attr(self):
67-
'''
66+
"""
6867
Returns the model instance field that references the activity actor
69-
'''
68+
"""
7069
return self.user
7170

7271
@property
7372
def activity_object_attr(self):
74-
'''
73+
"""
7574
Returns the reference to the object of the activity
76-
'''
75+
"""
7776
return self
7877

7978
@property
@@ -88,7 +87,7 @@ def activity_actor(self):
8887
def activity_verb(self):
8988
model_name = slugify(self.__class__.__name__)
9089
return model_name
91-
90+
9291
@property
9392
def activity_object(self):
9493
return create_reference(self.activity_object_attr)
@@ -103,20 +102,20 @@ def activity_time(self):
103102
if is_aware(self.created_at):
104103
atime = make_naive(atime, pytz.utc)
105104
return atime
106-
105+
107106
@property
108107
def activity_notify(self):
109108
pass
110-
109+
111110
def create_activity(self):
112111
extra_data = self.extra_activity_data
113112
if not extra_data:
114113
extra_data = {}
115-
114+
116115
to = self.activity_notify
117116
if to:
118-
extra_data['to'] = [f.id for f in to]
119-
117+
extra_data["to"] = [f.id for f in to]
118+
120119
activity = dict(
121120
actor=self.activity_actor,
122121
verb=self.activity_verb,

0 commit comments

Comments
 (0)