Skip to content

Commit

Permalink
add dotgit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbugli committed Nov 30, 2018
1 parent 1577927 commit e890bd9
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 164 deletions.
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
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",
],
)
2 changes: 1 addition & 1 deletion stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def connect(
# support for the heroku STREAM_URL syntax
if stream_url and not api_key:
pattern = re.compile(
"https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)", re.IGNORECASE
r"https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)", re.IGNORECASE
)
result = pattern.match(stream_url)
if result and len(result.groups()) == 4:
Expand Down
7 changes: 2 additions & 5 deletions stream/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
import json
import logging
import os
Expand Down Expand Up @@ -316,12 +315,10 @@ def follow_many(self, follows, activity_copy_limit=None):
"""
params = None

if activity_copy_limit != None:
if activity_copy_limit is not None:
params = dict(activity_copy_limit=activity_copy_limit)
token = self.create_jwt_token("follower", "*", feed_id="*")
return self.post(
"follow_many/", token, params=params, data=follows
)
return self.post("follow_many/", token, params=params, data=follows)

def update_activities(self, activities):
"""
Expand Down
2 changes: 1 addition & 1 deletion stream/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def follow(
"target": target_feed_id,
"target_token": self.client.feed(target_feed_slug, target_user_id).token,
}
if activity_copy_limit != None:
if activity_copy_limit is not None:
data["activity_copy_limit"] = activity_copy_limit
token = self.create_scope_token("follower", "write")
data.update(extra_data)
Expand Down
2 changes: 1 addition & 1 deletion stream/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _datetime_decoder(dict_):
# strings which are of type `str`. `jsondate` patches this for
# consistency so that `unicode` is always returned.
if value == "":
dict_[key] = u""
dict_[key] = ""
continue

if value is not None and isinstance(value, six.string_types):
Expand Down
1 change: 0 additions & 1 deletion stream/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .test_client import *
Loading

0 comments on commit e890bd9

Please sign in to comment.