Skip to content

Commit e890bd9

Browse files
committed
add dotgit hooks
1 parent 1577927 commit e890bd9

File tree

14 files changed

+147
-164
lines changed

14 files changed

+147
-164
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = E501,W503,E203,E731
3+
max-line-length = 110
4+
select = C,E,F,W,B,B950
5+
exclude = .eggs/*,docs/*,lib,src,bin,include,share

dotgit/hooks-wrapper

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# Runs all executable pre-commit-* hooks and exits after,
4+
# if any of them was not successful.
5+
#
6+
# Based on
7+
# https://github.com/ELLIOTTCABLE/Paws.js/blob/Master/Scripts/git-hooks/chain-hooks.sh
8+
# http://osdir.com/ml/git/2009-01/msg00308.html
9+
#
10+
# assumes your scripts are located at <repo-root>/bin/git/hooks
11+
exitcodes=()
12+
hookname=`basename $0`
13+
# our special hooks folder
14+
CUSTOM_HOOKS_DIR=$(git rev-parse --show-toplevel)/dotgit/hooks
15+
# find gits native hooks folder
16+
NATIVE_HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
17+
18+
# Run each hook, passing through STDIN and storing the exit code.
19+
# We don't want to bail at the first failure, as the user might
20+
# then bypass the hooks without knowing about additional issues.
21+
22+
for hook in $CUSTOM_HOOKS_DIR/$(basename $0)-*; do
23+
test -x "$hook" || continue
24+
$hook "$@"
25+
exitcodes+=($?)
26+
done
27+
28+
# check if there was a local hook that was moved previously
29+
if [ -f "$NATIVE_HOOKS_DIR/$hookname.local" ]; then
30+
out=`$NATIVE_HOOKS_DIR/$hookname.local "$@"`
31+
exitcodes+=($?)
32+
echo "$out"
33+
fi
34+
35+
# If any exit code isn't 0, bail.
36+
for i in "${exitcodes[@]}"; do
37+
[ "$i" == 0 ] || exit $i
38+
done

dotgit/hooks/pre-commit-format.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if ! black . --check -q; then
6+
black .
7+
echo "some files were not formatted correctly (black) commit aborted!"
8+
echo "your changes are still staged, you can accept formatting changes with git add or ignore them by adding --no-verify to git commit"
9+
exit 1
10+
fi
11+
12+
flake8
13+

dotgit/setup-hooks.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
# based on http://stackoverflow.com/a/3464399/1383268
3+
# assumes that the hooks-wrapper script is located at <repo-root>/bin/git/hooks-wrapper
4+
5+
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"
6+
# find gits native hooks folder
7+
HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
8+
9+
for hook in $HOOK_NAMES; do
10+
# If the hook already exists, is a file, and is not a symlink
11+
if [ ! -h $HOOKS_DIR/$hook ] && [ -f $HOOKS_DIR/$hook ]; then
12+
mv $HOOKS_DIR/$hook $HOOKS_DIR/$hook.local
13+
fi
14+
# create the symlink, overwriting the file if it exists
15+
# probably the only way this would happen is if you're using an old version of git
16+
# -- back when the sample hooks were not executable, instead of being named ____.sample
17+
ln -s -f ../../dotgit/hooks-wrapper $HOOKS_DIR/$hook
18+
done

fabfile.py

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

pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[tool.black]
2+
line-length = 88
3+
py36 = true
4+
include = '\.pyi?$'
5+
exclude = '''
6+
/(
7+
\.git
8+
| \.hg
9+
| \.egg
10+
| \.eggs
11+
| \.mypy_cache
12+
| \.tox
13+
| _build
14+
| \.venv
15+
| src
16+
| bin
17+
| stream_python\.egg-info
18+
| fabfile.py
19+
| lib
20+
| docs
21+
| buck-out
22+
| build
23+
| dist
24+
)/
25+
'''

setup.py

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,27 @@
66
from stream import __version__, __maintainer__, __email__, __license__
77
import sys
88

9-
unit = 'unittest2py3k' if sys.version_info > (3, 0, 0) else 'unittest2'
10-
tests_require = [
11-
unit,
12-
'pytest==3.2.5',
13-
'unittest2',
14-
'pytest-cov',
15-
'python-dateutil'
16-
]
9+
unit = "unittest2py3k" if sys.version_info > (3, 0, 0) else "unittest2"
10+
tests_require = [unit, "pytest==3.2.5", "unittest2", "pytest-cov", "python-dateutil"]
1711

18-
long_description = open('README.md', 'r').read()
12+
long_description = open("README.md", "r").read()
1913

20-
requests = 'requests>=2.3.0,<3'
14+
requests = "requests>=2.3.0,<3"
2115

2216
if sys.version_info < (2, 7, 9):
23-
requests = 'requests[security]>=2.4.1,<3'
17+
requests = "requests[security]>=2.4.1,<3"
2418

25-
install_requires = [
26-
'pycryptodomex==3.4.7',
27-
requests,
28-
'six>=1.8.0'
29-
]
19+
install_requires = ["pycryptodomex==3.4.7", requests, "six>=1.8.0"]
3020

3121
if sys.version_info < (2, 7, 0):
32-
install_requires.append('pyOpenSSL<18.0.0')
33-
install_requires.append('pyjwt>=1.3.0,<1.6.0')
34-
install_requires.append('pycparser<2.19')
22+
install_requires.append("pyOpenSSL<18.0.0")
23+
install_requires.append("pyjwt>=1.3.0,<1.6.0")
24+
install_requires.append("pycparser<2.19")
3525
else:
36-
install_requires.append('pyjwt>=1.3.0,<1.7.0')
26+
install_requires.append("pyjwt>=1.3.0,<1.7.0")
3727

3828

3929
class PyTest(TestCommand):
40-
4130
def finalize_options(self):
4231
TestCommand.finalize_options(self)
4332
self.test_args = []
@@ -46,43 +35,43 @@ def finalize_options(self):
4635
def run_tests(self):
4736
# import here, cause outside the eggs aren't loaded
4837
import pytest
49-
errno = pytest.main(
50-
'-v --cov=./')
38+
39+
errno = pytest.main("-v --cov=./")
5140
sys.exit(errno)
5241

5342

5443
setup(
55-
name='stream-python',
44+
name="stream-python",
5645
version=__version__,
5746
author=__maintainer__,
5847
author_email=__email__,
59-
url='http://github.com/GetStream/stream-python',
60-
description='Client for getstream.io. Build scalable newsfeeds & activity streams in a few hours instead of weeks.',
48+
url="http://github.com/GetStream/stream-python",
49+
description="Client for getstream.io. Build scalable newsfeeds & activity streams in a few hours instead of weeks.",
6150
long_description=long_description,
62-
long_description_content_type='text/markdown',
51+
long_description_content_type="text/markdown",
6352
license=__license__,
6453
packages=find_packages(),
6554
zip_safe=False,
6655
install_requires=install_requires,
67-
extras_require={'test': tests_require},
68-
cmdclass={'test': PyTest},
56+
extras_require={"test": tests_require},
57+
cmdclass={"test": PyTest},
6958
tests_require=tests_require,
7059
include_package_data=True,
7160
classifiers=[
72-
'Intended Audience :: Developers',
73-
'Intended Audience :: System Administrators',
74-
'Operating System :: OS Independent',
75-
'Topic :: Software Development',
76-
'Development Status :: 5 - Production/Stable',
77-
'License :: OSI Approved :: BSD License',
78-
'Natural Language :: English',
79-
'Programming Language :: Python :: 2.6',
80-
'Programming Language :: Python :: 2.7',
81-
'Programming Language :: Python :: 3',
82-
'Programming Language :: Python :: 3.4',
83-
'Programming Language :: Python :: 3.5',
84-
'Programming Language :: Python :: 3.6',
85-
'Programming Language :: Python :: 3.7',
86-
'Topic :: Software Development :: Libraries :: Python Modules',
61+
"Intended Audience :: Developers",
62+
"Intended Audience :: System Administrators",
63+
"Operating System :: OS Independent",
64+
"Topic :: Software Development",
65+
"Development Status :: 5 - Production/Stable",
66+
"License :: OSI Approved :: BSD License",
67+
"Natural Language :: English",
68+
"Programming Language :: Python :: 2.6",
69+
"Programming Language :: Python :: 2.7",
70+
"Programming Language :: Python :: 3",
71+
"Programming Language :: Python :: 3.4",
72+
"Programming Language :: Python :: 3.5",
73+
"Programming Language :: Python :: 3.6",
74+
"Programming Language :: Python :: 3.7",
75+
"Topic :: Software Development :: Libraries :: Python Modules",
8776
],
8877
)

stream/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def connect(
3333
# support for the heroku STREAM_URL syntax
3434
if stream_url and not api_key:
3535
pattern = re.compile(
36-
"https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)", re.IGNORECASE
36+
r"https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)", re.IGNORECASE
3737
)
3838
result = pattern.match(stream_url)
3939
if result and len(result.groups()) == 4:

stream/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from datetime import datetime
21
import json
32
import logging
43
import os
@@ -316,12 +315,10 @@ def follow_many(self, follows, activity_copy_limit=None):
316315
"""
317316
params = None
318317

319-
if activity_copy_limit != None:
318+
if activity_copy_limit is not None:
320319
params = dict(activity_copy_limit=activity_copy_limit)
321320
token = self.create_jwt_token("follower", "*", feed_id="*")
322-
return self.post(
323-
"follow_many/", token, params=params, data=follows
324-
)
321+
return self.post("follow_many/", token, params=params, data=follows)
325322

326323
def update_activities(self, activities):
327324
"""

stream/feed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def follow(
164164
"target": target_feed_id,
165165
"target_token": self.client.feed(target_feed_slug, target_user_id).token,
166166
}
167-
if activity_copy_limit != None:
167+
if activity_copy_limit is not None:
168168
data["activity_copy_limit"] = activity_copy_limit
169169
token = self.create_scope_token("follower", "write")
170170
data.update(extra_data)

0 commit comments

Comments
 (0)