Skip to content

Commit 1713c37

Browse files
authored
Better Topic Message Support. (#3)
- `uids` is NOT required parameter for `send_message` now. - `flake8` and its extensions compatibility. - `setuptools_scm` for version. - `pipenv` for dependencies management.
1 parent a4ba4e5 commit 1713c37

19 files changed

+139
-78
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,6 @@ dmypy.json
129129
.pyre/
130130

131131
# Custom
132+
.vscode
133+
Pipfile.lock
132134
config.py

MANIFEST.in

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

Makefile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
.PHONY: clean install dev lint pycodestyle pyflakes pylint test dist upload
1+
.PHONY: clean install lint flake8 pylint test dist upload
2+
3+
PIPENV := $(shell command -v pipenv > /dev/null && echo env)
4+
PIPRUN := $(shell command -v pipenv > /dev/null && echo pipenv run)
25

36
clean:
47
find . -name '*.pyc' -print0 | xargs -0 rm -f
@@ -9,21 +12,15 @@ clean:
912
-rm -rf .tox .coverage
1013

1114
install:
12-
pip install .
13-
14-
dev:
15-
pip install .[dev]
16-
17-
lint: pycodestyle pyflakes pylint
15+
pip$(PIPENV) install .
1816

19-
pycodestyle:
20-
-pycodestyle setup.py wxpusher
17+
lint: flake8 pylint
2118

22-
pyflakes:
23-
-pyflakes setup.py wxpusher
19+
flake8:
20+
${PIPRUN} flake8 setup.py wxpusher
2421

2522
pylint:
26-
-pylint setup.py wxpusher
23+
${PIPRUN} pylint setup.py wxpusher
2724

2825
test:
2926
tox

Pipfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
flake8 = "*"
8+
flake8-commas = "*"
9+
flake8-docstrings = "*"
10+
flake8-import-order = "*"
11+
pep8-naming = "*"
12+
pylint = "*"
13+
14+
[packages]
15+
wxpusher = {editable = true,path = "."}
16+
17+
[requires]
18+
python_version = "3"

README-en.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pip install -U wxpusher
2121

2222
```python
2323
from wxpusher import WxPusher
24-
WxPusher.send_message('<content>', '<uids>', '<appToken>')
24+
WxPusher.send_message('<content>',
25+
uids='<uids>',
26+
topic_ids='<topic_ids>',
27+
token='<appToken>')
2528
WxPusher.query_message('<messageId>')
2629
WxPusher.create_qrcode('<extra>', '<validTime>', '<appToken>')
2730
WxPusher.query_user('<page>', '<page_size>', '<appToken>')

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pip install -U wxpusher
2121

2222
```python
2323
from wxpusher import WxPusher
24-
WxPusher.send_message('<content>', '<uids>', '<appToken>')
24+
WxPusher.send_message('<content>',
25+
uids='<uids>',
26+
topic_ids='<topic_ids>',
27+
token='<appToken>')
2528
WxPusher.query_message('<messageId>')
2629
WxPusher.create_qrcode('<extra>', '<validTime>', '<appToken>')
2730
WxPusher.query_user('<page>', '<page_size>', '<appToken>')

VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

setup.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Python packaging for wxpusher.
5+
46
File: setup.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Python packaging for wxpusher.
89
"""
10+
from pkg_resources import DistributionNotFound
11+
from pkg_resources import get_distribution
12+
913
from setuptools import setup
1014

15+
NAME = 'wxpusher'
16+
1117
CLASSIFIERS = [
1218
'Development Status :: 4 - Beta',
1319
'Intended Audience :: Developers',
1420
'License :: OSI Approved :: Apache Software License',
1521
'Programming Language :: Python :: 3',
1622
'Programming Language :: Python :: 3 :: Only',
17-
'Topic :: Utilities'
23+
'Topic :: Utilities',
1824
]
1925

2026
INSTALL_REQUIRES = [
21-
'requests'
27+
'requests',
2228
]
2329

24-
DEV_REQUIRES = [
25-
'pycodestyle',
26-
'pyflakes',
27-
'pylint'
28-
]
29-
30-
TEST_REQUIRES = [
31-
'coverage',
32-
'nose'
33-
]
34-
35-
EXTRAS_REQUIRE = {
36-
'dev': DEV_REQUIRES,
37-
'test': TEST_REQUIRES
38-
}
39-
4030
DESCRIPTION = (
4131
'WxPusher Python SDK.'
4232
)
4333

44-
VERSION = open('VERSION').read().strip()
34+
KEYWORDS = [
35+
'wxpusher',
36+
'wechat',
37+
'weixin',
38+
'notification',
39+
'push-notification',
40+
'python-sdk',
41+
]
42+
43+
try:
44+
VERSION = f'v{get_distribution(NAME).version}'
45+
except DistributionNotFound:
46+
VERSION = 'master'
47+
4548
PROJECT_URL = 'https://github.com/wxpusher/wxpusher-sdk-python'
46-
BASE_URL = f'{PROJECT_URL}/blob/v{VERSION}'
49+
BASE_URL = f'{PROJECT_URL}/blob/{VERSION}'
4750

4851

4952
def readme():
@@ -54,19 +57,19 @@ def readme():
5457
return content
5558

5659

57-
setup(name='wxpusher',
58-
version=VERSION,
60+
setup(name=NAME,
5961
description=DESCRIPTION,
6062
long_description=readme(),
6163
long_description_content_type='text/markdown',
6264
classifiers=CLASSIFIERS,
63-
keywords='wxpusher wechat push-notification',
64-
url='https://github.com/wxpusher/wxpusher-sdk-python',
65+
keywords=' '.join(KEYWORDS),
66+
url=PROJECT_URL,
6567
author='Xuan (Sean) Hu',
6668
author_email='[email protected]',
6769
license='Apache License 2.0',
6870
packages=['wxpusher'],
71+
use_scm_version=True,
72+
setup_requires=['setuptools_scm'],
6973
install_requires=INSTALL_REQUIRES,
70-
extras_require=EXTRAS_REQUIRE,
7174
python_requires='>=3',
7275
include_package_data=True)

tox.ini

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py3
7+
envlist = py3, lint-py3
88

99
[testenv]
1010
deps =
11-
.[test]
11+
coverage
12+
nose
13+
pipenv
1214
commands =
15+
pipenv install --skip-lock
1316
nosetests --with-coverage --cover-erase --cover-package=wxpusher
17+
18+
[testenv:lint-py3]
19+
basepython = python3
20+
deps =
21+
pipenv
22+
commands=
23+
pipenv install --skip-lock --dev
24+
pipenv run make lint

wxpusher/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Init for WxPusher.
5+
46
File: __init__.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: init for WxPusher.
89
"""
9-
from .wxpusher import WxPusher
1010
from .exceptions import WxPusherException
1111
from .exceptions import WxPusherNoneTokenException
12+
from .wxpusher import WxPusher
1213

1314
__all__ = [
1415
'WxPusher',
1516
'WxPusherException',
16-
'WxPusherNoneTokenException'
17+
'WxPusherNoneTokenException',
1718
]
18-
19-
__version__ = open('VERSION').read().strip()

wxpusher/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
WxPusher Exceptions.
5+
46
File: exceptions.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: WxPusher Exceptions.
89
"""
910

1011

wxpusher/tests/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Init for unittest.
5+
46
File: __init__.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Init for unittest.
89
"""
910
from . import exceptions
1011

wxpusher/tests/config.sample.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Unittest configuration sample.
5+
46
File: config.sample.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Unittest configuration sample.
89
"""
910
# the `appToken` for test.
1011
TOKEN = ''
1112

1213
# the `uids` for test, note that it should be a list.
1314
UIDS = [
14-
''
15+
'',
16+
]
17+
18+
# the `topic_ids` for test, note that it should be a list.
19+
TOPIC_IDS = [
20+
'',
1521
]

wxpusher/tests/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Custom exceptions for unittest.
5+
46
File: exceptions.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Custom exceptions for unittest.
89
"""
910
from wxpusher import WxPusherException
1011

wxpusher/tests/test_create_qrcode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Unittest for creating qrcode.
5+
46
File: test_create_qrcode.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Unittest for creating qrcode.
89
"""
910
import unittest
1011

@@ -18,12 +19,13 @@ class TestCreateQRCode(unittest.TestCase):
1819

1920
@classmethod
2021
def setUpClass(cls):
22+
"""Set up for class."""
2123
WxPusher.default_token = config.TOKEN
2224

2325
def test_create_qrcode(self):
2426
"""Positive case for creating qrcode."""
2527
res = WxPusher.create_qrcode(
26-
self.test_create_qrcode.__doc__
28+
self.test_create_qrcode.__doc__,
2729
)
2830
self.assertIsInstance(res, dict)
2931
self.assertIn('code', res)

wxpusher/tests/test_query_message.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Unittest for querying message.
5+
46
File: test_send_message.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Unittest for querying message.
89
"""
9-
import unittest
1010
import random
11+
import unittest
1112

1213
from wxpusher import WxPusher
1314

wxpusher/tests/test_query_user.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
"""
4+
Unittest for querying user.
5+
46
File: test_send_message.py
57
Author: huxuan
68
Email: i(at)huxuan.org
7-
Description: Unittest for querying user.
89
"""
910
import random
1011
import unittest
@@ -19,12 +20,13 @@ class TestSendMessage(unittest.TestCase):
1920

2021
@classmethod
2122
def setUpClass(cls):
23+
"""Set up for class."""
2224
WxPusher.default_token = config.TOKEN
2325

2426
def test_query_user(self):
2527
"""Positive case for querying user."""
2628
res = WxPusher.query_user(
27-
1, random.randint(1, 99)
29+
1, random.randint(1, 99),
2830
)
2931
self.assertIsInstance(res, dict)
3032
self.assertIn('code', res)

0 commit comments

Comments
 (0)