Skip to content

Commit ad9d03f

Browse files
committed
feat: Update for modern python
This updates things to use more modern python practices. This includes: * Adding a pyproject.toml file * Add type hints **BREAKING CHANGE** `Webpusher.encode` will now return a `NoData` exception if no data is present to encode. Chances are you probably won't be impacted by this change since most push messages contain data, but one never knows. This alters the prior behavior where it would return `None`. Includes fixes from #152 by https://github.com/TobeTek (Thanks!)
1 parent c5507b2 commit ad9d03f

10 files changed

+616
-303
lines changed

.gitignore

+103-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ __pycache__/
88

99
# Distribution / packaging
1010
.Python
11-
env/
1211
bin/
1312
build/
1413
develop-eggs/
@@ -23,9 +22,12 @@ lib64/
2322
parts/
2423
sdist/
2524
var/
25+
wheels/
26+
share/python-wheels/
2627
*.egg-info/
2728
.installed.cfg
2829
*.egg
30+
MANIFEST
2931

3032
# PyInstaller
3133
# Usually these files are written by a python script from a template
@@ -40,27 +42,124 @@ pip-delete-this-directory.txt
4042
# Unit test / coverage reports
4143
htmlcov/
4244
.tox/
45+
.nox/
4346
.coverage
4447
.coverage.*
4548
.cache
4649
nosetests.xml
4750
coverage.xml
48-
*,cover
51+
*.cover
52+
*.py,cover
4953
.hypothesis/
54+
.pytest_cache/
55+
cover/
5056

5157
# Translations
5258
*.mo
5359
*.pot
5460

5561
# Django stuff:
5662
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
5773

5874
# Sphinx documentation
5975
docs/_build/
6076

6177
# PyBuilder
78+
.pybuilder/
6279
target/
6380

64-
#Ipython Notebook
81+
# Jupyter Notebook
6582
.ipynb_checkpoints
66-
*.swp
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
# .python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
#poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/#use-with-ide
113+
.pdm.toml
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/
164+
165+
.vscode/

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# I am terrible at keeping this up-to-date.
22

3+
## 2.0.0 (2024-01-02)
4+
chore: Update to modern python practices
5+
* include pyproject.toml file
6+
* use python typing
7+
* update to use pytest
8+
9+
*BREAKING_CHANGE*
10+
`Webpusher.encode` will now return a `NoData` exception if no data is present to encode. Chances are
11+
you probably won't be impacted by this change since most push messages contain data, but one never knows.
12+
This alters the prior behavior where it would return `None`.
13+
314
## 1.14.0 (2021-07-28)
415
bug: accept all VAPID key instances (thanks @mthu)
516

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ webpush(subscription_info,
6060
This will encode `data`, add the appropriate VAPID auth headers if required and send it to the push server identified
6161
in the `subscription_info` block.
6262

63-
**Parameters**
63+
##### Parameters
6464

6565
_subscription_info_ - The `dict` of the subscription info (described above).
6666

@@ -85,7 +85,7 @@ e.g. the output of:
8585
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
8686
```
8787

88-
**Example**
88+
##### Example
8989

9090
```python
9191
from pywebpush import webpush, WebPushException
@@ -127,7 +127,7 @@ The following methods are available:
127127

128128
Send the data using additional parameters. On error, returns a `WebPushException`
129129

130-
**Parameters**
130+
##### Parameters
131131

132132
_data_ Binary string of data to send
133133

@@ -148,7 +148,7 @@ named `encrpypted.data`. This command is meant to be used for debugging purposes
148148
_timeout_ timeout for requests POST query.
149149
See [requests documentation](http://docs.python-requests.org/en/master/user/quickstart/#timeouts).
150150

151-
**Example**
151+
##### Example
152152

153153
to send from Chrome using the old GCM mode:
154154

@@ -160,13 +160,17 @@ WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
160160

161161
Encode the `data` for future use. On error, returns a `WebPushException`
162162

163-
**Parameters**
163+
##### Parameters
164164

165165
_data_ Binary string of data to send
166166

167167
_content_encoding_ ECE content encoding type (defaults to "aes128gcm")
168168

169-
**Example**
169+
*Note* This will return a `NoData` exception if the data is not present or empty. It is completely
170+
valid to send a WebPush notification with no data, but encoding is a no-op in that case. Best not
171+
to call it if you don't have data.
172+
173+
##### Example
170174

171175
```python
172176
encoded_data = WebPush(subscription_info).encode(data)

pyproject.toml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
dependencies = [
7+
"wheel",
8+
"aiohttp",
9+
"cryptography>=2.6.1",
10+
"http-ece>=1.1.0",
11+
"requests>=2.21.0",
12+
"six>=1.15.0",
13+
"py-vapid>=1.7.0",
14+
]
15+
name = "pywebpush"
16+
authors = [{ name = "JR Conlin", email = "[email protected]" }]
17+
description = "WebPush publication library"
18+
readme = "README.md"
19+
license = { file = "LICENSE" }
20+
keywords = ["webpush", "vapid", "notification"]
21+
classifiers = [
22+
"Topic :: Internet :: WWW/HTTP",
23+
"Programming Language :: Python :: Implementation :: PyPy",
24+
"Programming Language :: Python",
25+
"Programming Language :: Python :: 3",
26+
]
27+
version = "2.0.0"
28+
[project.urls]
29+
Homepage = "https://github.com/web-push-libs/pywebpush"
30+
31+
[project.optional-dependencies]
32+
dev = ["black", "mock", "pytest"]
33+
34+
[project.scripts]
35+
pywebpush = "pywebpush.__main__:main"

0 commit comments

Comments
 (0)