Skip to content

Commit c158097

Browse files
authored
feat: Update for modern python (#158)
* 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 7bb3b19 commit c158097

13 files changed

+695
-317
lines changed

.circleci/config.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SOP Python circleci file
2+
3+
version: 2.1
4+
5+
orbs:
6+
python: circleci/[email protected]
7+
8+
jobs:
9+
build_and_test:
10+
executor: python/default
11+
steps:
12+
- checkout
13+
- python/install-packages:
14+
pkg-manager: pip
15+
- run:
16+
name: Build
17+
command: pip3 install -r test-requirements.txt
18+
- run:
19+
name: Run tests
20+
command: python -m pytest pywebpush
21+
- persist_to_workspace:
22+
root: ~/project
23+
paths:
24+
- .
25+
26+
workflows:
27+
build_and_test:
28+
jobs:
29+
- build_and_test

.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

PULL_REQUEST_TEMPLATE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Description
2+
3+
*_NOTE_*: All commits MUST be signed! See https://docs.github.com/en/github/authenticating-to-github/signing-commits
4+
5+
_Describe these changes._
6+
7+
## Testing
8+
9+
_How should reviewers test?_
10+
11+
## Issue(s)
12+
13+
Closes _#IssueNumber_

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ make of that what you will.
1111

1212
## Installation
1313

14-
You'll need to run `python -m venv venv`.
15-
Then
14+
To work with this repo locally, you'll need to run `python -m venv venv`.
15+
Then `venv/bin/pip install --editable .`
1616

17-
```bash
18-
venv/bin/pip install -r requirements.txt
19-
venv/bin/python setup.py develop
20-
```
2117

2218
## Usage
2319

@@ -60,7 +56,7 @@ webpush(subscription_info,
6056
This will encode `data`, add the appropriate VAPID auth headers if required and send it to the push server identified
6157
in the `subscription_info` block.
6258

63-
**Parameters**
59+
##### Parameters
6460

6561
_subscription_info_ - The `dict` of the subscription info (described above).
6662

@@ -85,7 +81,7 @@ e.g. the output of:
8581
openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem
8682
```
8783

88-
**Example**
84+
##### Example
8985

9086
```python
9187
from pywebpush import webpush, WebPushException
@@ -127,7 +123,7 @@ The following methods are available:
127123

128124
Send the data using additional parameters. On error, returns a `WebPushException`
129125

130-
**Parameters**
126+
##### Parameters
131127

132128
_data_ Binary string of data to send
133129

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

151-
**Example**
147+
##### Example
152148

153149
to send from Chrome using the old GCM mode:
154150

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

161157
Encode the `data` for future use. On error, returns a `WebPushException`
162158

163-
**Parameters**
159+
##### Parameters
164160

165161
_data_ Binary string of data to send
166162

167163
_content_encoding_ ECE content encoding type (defaults to "aes128gcm")
168164

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

171171
```python
172172
encoded_data = WebPush(subscription_info).encode(data)

entry_points.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[console_scripts]
2+
pywebpush = "pywebpush.__main__:main"

pyproject.toml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[build-system]
2+
# This uses the semi-built-in "setuptools" which is currently the
3+
# python pariah, but there are a lot of behaviors that still carry.
4+
# This will draw a lot of information from `setup.py` and `setup.cfg`
5+
# For more info see https://packaging.python.org/en/latest/
6+
# (although, be fore-warned, it gets fairly wonky and obsessed with
7+
# details that you may not care about.)
8+
requires = ["setuptools", "wheel"]
9+
build-backend = "setuptools.build_meta"
10+
11+
[project]
12+
# `dependencies` are taken from `setup.py` and include the contents of the
13+
# `requirements.txt` file
14+
name = "pywebpush"
15+
authors = [{ name = "JR Conlin", email = "[email protected]" }]
16+
description = "WebPush publication library"
17+
readme = "README.md"
18+
# Use the LICENSE file for our license, since "MPL2" isn't included in the
19+
# canonical list
20+
license = { file = "LICENSE" }
21+
keywords = ["webpush", "vapid", "notification"]
22+
classifiers = [
23+
"Topic :: Internet :: WWW/HTTP",
24+
"Programming Language :: Python :: Implementation :: PyPy",
25+
"Programming Language :: Python",
26+
"Programming Language :: Python :: 3",
27+
]
28+
# use the following fields defined in the setup.py file
29+
# (When the guides talk about something being "dynamic", they
30+
# want you to add the field here.
31+
dynamic = ["version", "entry-points"]
32+
33+
[project.urls]
34+
Homepage = "https://github.com/web-push-libs/pywebpush"
35+
36+
[project.optional-dependencies]
37+
dev = ["black", "mock", "pytest"]
38+
39+
# create the `pywebpush` helper using `python -m pip install --editable .`
40+
[project.scripts]
41+
pywebpush = "pywebpush.__main__:main"

0 commit comments

Comments
 (0)