Skip to content

Commit

Permalink
feat: Update for modern python
Browse files Browse the repository at this point in the history
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!)
  • Loading branch information
jrconlin committed Dec 28, 2023
1 parent c5507b2 commit ad9d03f
Show file tree
Hide file tree
Showing 10 changed files with 616 additions and 303 deletions.
107 changes: 103 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ __pycache__/

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
Expand All @@ -23,9 +22,12 @@ lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -40,27 +42,124 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

#Ipython Notebook
# Jupyter Notebook
.ipynb_checkpoints
*.swp

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode/
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# I am terrible at keeping this up-to-date.

## 2.0.0 (2024-01-02)
chore: Update to modern python practices
* include pyproject.toml file
* use python typing
* update to use pytest

*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`.

## 1.14.0 (2021-07-28)
bug: accept all VAPID key instances (thanks @mthu)

Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ webpush(subscription_info,
This will encode `data`, add the appropriate VAPID auth headers if required and send it to the push server identified
in the `subscription_info` block.

**Parameters**
##### Parameters

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

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

**Example**
##### Example

```python
from pywebpush import webpush, WebPushException
Expand Down Expand Up @@ -127,7 +127,7 @@ The following methods are available:

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

**Parameters**
##### Parameters

_data_ Binary string of data to send

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

**Example**
##### Example

to send from Chrome using the old GCM mode:

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

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

**Parameters**
##### Parameters

_data_ Binary string of data to send

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

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

##### Example

```python
encoded_data = WebPush(subscription_info).encode(data)
Expand Down
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
dependencies = [
"wheel",
"aiohttp",
"cryptography>=2.6.1",
"http-ece>=1.1.0",
"requests>=2.21.0",
"six>=1.15.0",
"py-vapid>=1.7.0",
]
name = "pywebpush"
authors = [{ name = "JR Conlin", email = "[email protected]" }]
description = "WebPush publication library"
readme = "README.md"
license = { file = "LICENSE" }
keywords = ["webpush", "vapid", "notification"]
classifiers = [
"Topic :: Internet :: WWW/HTTP",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
version = "2.0.0"
[project.urls]
Homepage = "https://github.com/web-push-libs/pywebpush"

[project.optional-dependencies]
dev = ["black", "mock", "pytest"]

[project.scripts]
pywebpush = "pywebpush.__main__:main"
Loading

0 comments on commit ad9d03f

Please sign in to comment.