Skip to content

Commit 20a79b4

Browse files
authored
feat: add type hints and mypy
1 parent 182386d commit 20a79b4

27 files changed

+1274
-1458
lines changed

.github/workflows/ci.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ name: build
22
on:
33
push:
44
branches:
5-
- 'master'
5+
- "master"
66
pull_request:
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
build:
1014
runs-on: ubuntu-latest
1115
strategy:
1216
max-parallel: 1
1317
matrix:
14-
python: [3.6, 3.7, 3.8, 3.9, '3.10']
18+
python: [3.6, 3.7, 3.8, 3.9, "3.10"]
1519
steps:
1620
- uses: actions/checkout@v2
1721
- uses: actions/setup-python@v2
1822
with:
1923
python-version: ${{ matrix.python }}
2024

21-
- name: Add pip bin to PATH
22-
run: |
23-
echo "/home/runner/.local/bin" >> $GITHUB_PATH
24-
2525
- name: Install deps with ${{ matrix.python }}
2626
run: pip install ".[test, ci]"
2727

@@ -33,6 +33,5 @@ jobs:
3333
env:
3434
STREAM_KEY: ${{ secrets.STREAM_KEY }}
3535
STREAM_SECRET: ${{ secrets.STREAM_SECRET }}
36-
run: |
37-
python setup.py install
38-
make test
36+
PYTHONPATH: ${{ github.workspace }}
37+
run: make test

.github/workflows/reviewdog.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: Install deps
24+
run: pip install ".[ci]"
25+
26+
- name: Reviewdog
27+
env:
28+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: make reviewdog

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var/
2222
.installed.cfg
2323
*.egg
2424
include/
25+
.DS_Store
2526

2627
# Installer logs
2728
pip-log.txt
@@ -42,6 +43,7 @@ coverage.xml
4243
.mr.developer.cfg
4344
.project
4445
.pydevproject
46+
.coverage*
4547

4648
# Rope
4749
.ropeproject
@@ -62,6 +64,7 @@ pip-selfcheck.json
6264
.idea
6365
.vscode
6466
*,cover
67+
.mypy_cache
6568
.eggs
6669
.env
6770
.envrc

MANIFEST.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
include README.md
1+
include README.md
2+
include stream_chat/py.typed

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ help: ## Display this help message
1111

1212
lint: ## Run linters
1313
black --check stream_chat
14-
flake8 --ignore=E501,E225,W293,W503,F401 stream_chat
14+
flake8 --ignore=E501,W503 stream_chat
15+
mypy stream_chat
1516

1617
lint-fix:
1718
black stream_chat
1819

1920
test: ## Run tests
20-
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) python setup.py test
21+
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) pytest --cov=stream_chat --cov-report=xml stream_chat/tests
2122

2223
check: lint test ## Run linters + tests
24+
25+
reviewdog:
26+
black --check --diff --quiet stream_chat | reviewdog -f=diff -f.diff.strip=0 -filter-mode="diff_context" -name=black -reporter=github-pr-review
27+
flake8 --ignore=E501,W503 stream_chat | reviewdog -f=flake8 -name=flake8 -reporter=github-pr-review
28+
mypy --show-column-numbers --show-absolute-path stream_chat | reviewdog -efm="%f:%l:%c: %t%*[^:]: %m" -name=mypy -reporter=github-pr-review

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# stream-chat-python
22

3-
[![build](https://github.com/GetStream/stream-chat-python/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-python/actions) [![PyPI version](https://badge.fury.io/py/stream-chat.svg)](http://badge.fury.io/py/stream-chat) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stream-chat.svg)
3+
[![build](https://github.com/GetStream/stream-chat-python/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-python/actions) [![PyPI version](https://badge.fury.io/py/stream-chat.svg)](http://badge.fury.io/py/stream-chat) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stream-chat.svg) [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
44

55
the official Python API client for [Stream chat](https://getstream.io/chat/) a service for building chat applications.
66

@@ -37,6 +37,8 @@ pip install stream-chat
3737

3838
### Quickstart
3939

40+
> :bulb: The library is almost 100% typed. Feel free to enable [mypy](https://github.com/python/mypy) for our library. We will introduce more improvements in the future in this area.
41+
4042
#### Sync
4143

4244
```python
@@ -125,7 +127,7 @@ In order to release new version you need to be a maintainer on Pypi.
125127
- Update the version on setup.py
126128
- Commit and push to Github
127129
- Create a new tag for the version (eg. `v2.9.0`)
128-
- Create a new dist with python `python setup.py sdist`
129-
- Upload the new distributable with twine `twine upload dist/stream-chat-VERSION-NAME.tar.gz`
130+
- Create a new dist with python `python setup.py sdist bdist_wheel`
131+
- Upload the new distributable with twine `twine upload dist/*`
130132

131133
If unsure you can also test using the Pypi test servers `twine upload --repository-url https://test.pypi.org/legacy/ dist/stream-chat-VERSION-NAME.tar.gz`

pyproject.toml

+10
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ exclude = '''
2323
| dist
2424
)/
2525
'''
26+
27+
[tool.mypy]
28+
disallow_untyped_defs = true
29+
disallow_untyped_calls = true
30+
check_untyped_defs = true
31+
warn_unused_configs = true
32+
33+
[[tool.mypy.overrides]]
34+
module = "stream_chat.tests.*"
35+
ignore_errors = true

setup.py

+22-36
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,51 @@
1-
import sys
2-
31
from setuptools import find_packages, setup
4-
from setuptools.command.test import test as TestCommand
52

63
install_requires = [
7-
"pycryptodomex>=3.8.1,<4",
84
"requests>=2.22.0,<3",
9-
"chardet>=2.0.0,<4",
105
"aiodns>=2.0.0",
116
"aiohttp>=3.6.0,<4",
127
"aiofile>=3.1,<4",
138
"pyjwt>=2.0.0,<3",
9+
"typing_extensions; python_version < '3.8'",
1410
]
15-
long_description = open("README.md", "r").read()
1611
tests_require = ["pytest", "pytest-asyncio"]
17-
ci_require = ["black", "flake8", "pytest-cov"]
12+
ci_require = [
13+
"black",
14+
"flake8",
15+
"flake8-bugbear",
16+
"pytest-cov",
17+
"mypy",
18+
"types-requests",
19+
]
20+
21+
with open("README.md", "r") as f:
22+
long_description = f.read()
1823

1924
about = {}
25+
2026
with open("stream_chat/__pkg__.py") as fp:
2127
exec(fp.read(), about)
2228

23-
24-
class PyTest(TestCommand):
25-
def finalize_options(self):
26-
TestCommand.finalize_options(self)
27-
self.test_args = []
28-
self.test_suite = True
29-
30-
def run_tests(self):
31-
# import here, cause outside the eggs aren't loaded
32-
import pytest
33-
34-
pytest_cmd = ["stream_chat/", "-v"]
35-
36-
try:
37-
pytest_cmd += [
38-
"--cov=stream_chat/",
39-
"--cov-report=xml",
40-
]
41-
except ImportError:
42-
pass
43-
44-
errno = pytest.main(pytest_cmd)
45-
sys.exit(errno)
46-
47-
4829
setup(
4930
name="stream-chat",
50-
cmdclass={"test": PyTest},
5131
version=about["__version__"],
5232
author=about["__maintainer__"],
5333
author_email=about["__email__"],
54-
url="http://github.com/GetStream/chat-py",
34+
url="https://github.com/GetStream/stream-chat-python",
35+
project_urls={
36+
"Bug Tracker": "https://github.com/GetStream/stream-chat-python/issues",
37+
"Documentation": "https://getstream.io/activity-feeds/docs/python/?language=python",
38+
"Release Notes": "https://github.com/GetStream/stream-chat-python/releases/tag/v{}".format(
39+
about["__version__"]
40+
),
41+
},
5542
description="Client for Stream Chat.",
5643
long_description=long_description,
5744
long_description_content_type="text/markdown",
58-
packages=find_packages(),
45+
packages=find_packages(exclude=["*tests*"]),
5946
zip_safe=False,
6047
install_requires=install_requires,
6148
extras_require={"test": tests_require, "ci": ci_require},
62-
tests_require=tests_require,
6349
include_package_data=True,
6450
python_requires=">=3.6",
6551
classifiers=[

stream_chat/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .client import StreamChat
22
from .async_chat import StreamChatAsync
3+
4+
__all__ = ["StreamChat", "StreamChatAsync"]

stream_chat/__pkg__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "Tommaso Barbugli"
2-
__copyright__ = "Copyright 2019-2021, Stream.io, Inc"
2+
__copyright__ = "Copyright 2019-2022, Stream.io, Inc"
33
__version__ = "3.16.0"
44
__maintainer__ = "Tommaso Barbugli"
55
__email__ = "[email protected]"

stream_chat/async_chat/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .client import StreamChatAsync
2+
3+
__all__ = ["StreamChatAsync"]

0 commit comments

Comments
 (0)