Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E501,W503,E203,E731
max-line-length = 110
select = C,E,F,W,B,B950
exclude = .eggs/*,docs/*,lib,src,bin,include,share
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: python
sudo: false
python:
- 2.6
- 2.7
Expand All @@ -12,13 +11,13 @@ matrix:
include:
- python: 3.7
dist: xenial
sudo: true

cache: pip

install:
- pip install -r dev_requirements.txt
script:
- echo $STREAM_KEY
- py.test -lv --cov=./
after_script:
- "pep8 --exclude=migrations --ignore=E501,E225,W293 stream"
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Documentation for this Python client are available at the [Stream website](https
### Usage

```python
import datetime

# Instantiate a new client
import stream
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET')
Expand Down Expand Up @@ -116,15 +118,11 @@ client.activity_partial_update(id=activity_id, set=set, unset=unset)
# ...or by combination of foreign_id and time
client.activity_partial_update(foreign_id=foreign_id, time=activity_time, set=set, unset=unset)

# Generating tokens for client side usage (JS client)
token = user_feed_1.token
# Javascript client side feed initialization
# user1 = client.feed('user', '1', '{{ token }}');
# Generating user token for client side usage (JS client)
user_token = client.create_user_token("user-42")

# Generate a read-only token for client side usage (JS client)
readonly_token = user_feed_1.get_readonly_token()
# Javascript client side feed initialization
# user1 = client.feed('user', '1', '{{ readonly_token }}');
# client = stream.connect(apiKey, userToken, appId);

# Generate a redirect url for the Stream Analytics platform to track
# events/impressions on url clicks
Expand Down Expand Up @@ -164,6 +162,15 @@ py.test --cov stream --cov-report html
LOCAL=true py.test
```

Install black and flake8

```
pip install black
pip install flake8
```

Install git hooks to avoid pushing invalid code (git commit will run black and flak8)

### Releasing a new version

In order to release new version you need to be a maintainer on Pypi.
Expand Down
38 changes: 38 additions & 0 deletions dotgit/hooks-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Runs all executable pre-commit-* hooks and exits after,
# if any of them was not successful.
#
# Based on
# https://github.com/ELLIOTTCABLE/Paws.js/blob/Master/Scripts/git-hooks/chain-hooks.sh
# http://osdir.com/ml/git/2009-01/msg00308.html
#
# assumes your scripts are located at <repo-root>/bin/git/hooks
exitcodes=()
hookname=`basename $0`
# our special hooks folder
CUSTOM_HOOKS_DIR=$(git rev-parse --show-toplevel)/dotgit/hooks
# find gits native hooks folder
NATIVE_HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks

# Run each hook, passing through STDIN and storing the exit code.
# We don't want to bail at the first failure, as the user might
# then bypass the hooks without knowing about additional issues.

for hook in $CUSTOM_HOOKS_DIR/$(basename $0)-*; do
test -x "$hook" || continue
$hook "$@"
exitcodes+=($?)
done

# check if there was a local hook that was moved previously
if [ -f "$NATIVE_HOOKS_DIR/$hookname.local" ]; then
out=`$NATIVE_HOOKS_DIR/$hookname.local "$@"`
exitcodes+=($?)
echo "$out"
fi

# If any exit code isn't 0, bail.
for i in "${exitcodes[@]}"; do
[ "$i" == 0 ] || exit $i
done
13 changes: 13 additions & 0 deletions dotgit/hooks/pre-commit-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

if ! black . --check -q; then
black .
echo "some files were not formatted correctly (black) commit aborted!"
echo "your changes are still staged, you can accept formatting changes with git add or ignore them by adding --no-verify to git commit"
exit 1
fi

flake8

18 changes: 18 additions & 0 deletions dotgit/setup-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# based on http://stackoverflow.com/a/3464399/1383268
# assumes that the hooks-wrapper script is located at <repo-root>/bin/git/hooks-wrapper

HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc pre-push"
# find gits native hooks folder
HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks

for hook in $HOOK_NAMES; do
# If the hook already exists, is a file, and is not a symlink
if [ ! -h $HOOKS_DIR/$hook ] && [ -f $HOOKS_DIR/$hook ]; then
mv $HOOKS_DIR/$hook $HOOKS_DIR/$hook.local
fi
# create the symlink, overwriting the file if it exists
# probably the only way this would happen is if you're using an old version of git
# -- back when the sample hooks were not executable, instead of being named ____.sample
ln -s -f ../../dotgit/hooks-wrapper $HOOKS_DIR/$hook
done
85 changes: 0 additions & 85 deletions fabfile.py

This file was deleted.

25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tool.black]
line-length = 88
py36 = true
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.egg
| \.eggs
| \.mypy_cache
| \.tox
| _build
| \.venv
| src
| bin
| stream_python\.egg-info
| fabfile.py
| lib
| docs
| buck-out
| build
| dist
)/
'''
77 changes: 33 additions & 44 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,27 @@
from stream import __version__, __maintainer__, __email__, __license__
import sys

unit = 'unittest2py3k' if sys.version_info > (3, 0, 0) else 'unittest2'
tests_require = [
unit,
'pytest==3.2.5',
'unittest2',
'pytest-cov',
'python-dateutil'
]
unit = "unittest2py3k" if sys.version_info > (3, 0, 0) else "unittest2"
tests_require = [unit, "pytest==3.2.5", "unittest2", "pytest-cov", "python-dateutil"]

long_description = open('README.md', 'r').read()
long_description = open("README.md", "r").read()

requests = 'requests>=2.3.0,<3'
requests = "requests>=2.3.0,<3"

if sys.version_info < (2, 7, 9):
requests = 'requests[security]>=2.4.1,<3'
requests = "requests[security]>=2.4.1,<3"

install_requires = [
'pycryptodomex==3.4.7',
requests,
'six>=1.8.0'
]
install_requires = ["pycryptodomex==3.4.7", requests, "six>=1.8.0"]

if sys.version_info < (2, 7, 0):
install_requires.append('pyOpenSSL<18.0.0')
install_requires.append('pyjwt>=1.3.0,<1.6.0')
install_requires.append('pycparser<2.19')
install_requires.append("pyOpenSSL<18.0.0")
install_requires.append("pyjwt>=1.3.0,<1.6.0")
install_requires.append("pycparser<2.19")
else:
install_requires.append('pyjwt>=1.3.0,<1.7.0')
install_requires.append("pyjwt>=1.3.0,<1.7.0")


class PyTest(TestCommand):

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
Expand All @@ -46,43 +35,43 @@ def finalize_options(self):
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(
'-v --cov=./')

errno = pytest.main("-v --cov=./")
sys.exit(errno)


setup(
name='stream-python',
name="stream-python",
version=__version__,
author=__maintainer__,
author_email=__email__,
url='http://github.com/GetStream/stream-python',
description='Client for getstream.io. Build scalable newsfeeds & activity streams in a few hours instead of weeks.',
url="http://github.com/GetStream/stream-python",
description="Client for getstream.io. Build scalable newsfeeds & activity streams in a few hours instead of weeks.",
long_description=long_description,
long_description_content_type='text/markdown',
long_description_content_type="text/markdown",
license=__license__,
packages=find_packages(),
zip_safe=False,
install_requires=install_requires,
extras_require={'test': tests_require},
cmdclass={'test': PyTest},
extras_require={"test": tests_require},
cmdclass={"test": PyTest},
tests_require=tests_require,
include_package_data=True,
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Operating System :: OS Independent',
'Topic :: Software Development',
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Libraries :: Python Modules',
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Operating System :: OS Independent",
"Topic :: Software Development",
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
Loading