Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update for modern python #158

Merged
merged 11 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SOP Python circleci file

version: 2.1

orbs:
python: circleci/[email protected]

jobs:
build_and_test:
executor: python/default
steps:
- checkout
- python/install-packages:
pkg-manager: pip
- run:
name: Build
command: pip3 install -r test-requirements.txt
- run:
name: Run tests
command: python -m pytest pywebpush
- persist_to_workspace:
root: ~/project
paths:
- .

workflows:
build_and_test:
jobs:
- build_and_test
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
13 changes: 13 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Description

*_NOTE_*: All commits MUST be signed! See https://docs.github.com/en/github/authenticating-to-github/signing-commits

_Describe these changes._

## Testing

_How should reviewers test?_

## Issue(s)

Closes _#IssueNumber_
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ make of that what you will.

## Installation

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

```bash
venv/bin/pip install -r requirements.txt
venv/bin/python setup.py develop
```

## Usage

Expand Down Expand Up @@ -60,7 +56,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 +81,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 +123,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 +144,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 +156,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
2 changes: 2 additions & 0 deletions entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[console_scripts]
pywebpush = "pywebpush.__main__:main"
41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[build-system]
# This uses the semi-built-in "setuptools" which is currently the
# python pariah, but there are a lot of behaviors that still carry.
# This will draw a lot of information from `setup.py` and `setup.cfg`
# For more info see https://packaging.python.org/en/latest/
# (although, be fore-warned, it gets fairly wonky and obsessed with
# details that you may not care about.)
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
# `dependencies` are taken from `setup.py` and include the contents of the
# `requirements.txt` file
name = "pywebpush"
authors = [{ name = "JR Conlin", email = "[email protected]" }]
description = "WebPush publication library"
readme = "README.md"
# Use the LICENSE file for our license, since "MPL2" isn't included in the
# canonical list
license = { file = "LICENSE" }
keywords = ["webpush", "vapid", "notification"]
classifiers = [
"Topic :: Internet :: WWW/HTTP",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
# use the following fields defined in the setup.py file
# (When the guides talk about something being "dynamic", they
# want you to add the field here.
dynamic = ["version", "entry-points"]

[project.urls]
Homepage = "https://github.com/web-push-libs/pywebpush"

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

# create the `pywebpush` helper using `python -m pip install --editable .`
[project.scripts]
pywebpush = "pywebpush.__main__:main"
Loading