pypush
pypush copied to clipboard
Rewrite: Initial structure
Trying to get the ball rolling here, this is my proposal for an initial structure of the rewrite.
I've structured it so that APNs will eventually be published as it's own independent PyPI package.
The first stage of pypush's rewrite will be to rip everything out, and polish off just APNs by itself.
Still need:
- [ ] Rewrite actual APNs implementation, using
asynciothis time - [ ] Work out API for device details and versions
Maybe this time I should go ahead and implement https://github.com/JJTech0130/pypush/issues/61 right off the bat
Here's how the package structure and API is looking:
pypush-apns and pypush are the package names for now. Might need to be renamed if I can't get pypush on pypi
pypush depends on pypush-apns, but APNs can be used independently
The namespace means you can use it like this:
import pypush.apns
no matter how you install it
Using asyncio over trio for the added API flexibility, though it does bring some additional pitfalls and possible footguns...
Can now provide 2 APIs:
@pytest.mark.asyncio
async def test_connect():
connection = apns.connection.Connection(certificate, key)
await connection.connect()
assert connection.connected == True
await connection.aclose()
assert connection.connected == False
and
@pytest.mark.asyncio
async def test_with_block():
async with apns.connection.Connection(certificate, key) as connection:
assert connection.connected == True
assert connection.connected == False
I store both the event loop and a list of tasks to cancel inside Connection, I'm not sure if that is the best way to use asyncio?
Honestly probably going to stick with recommending
pip install git+https://github.com/JJTech0130/pypush
rather than deal with publishing to PyPi for now
(pip install git+https://github.com/JJTech0130/pypush@initial-rewrite-structure for this branch)
@JJTech0130 Please contact me
apnsproxy is now working: it allows you to see the APNs packets that your local machine is sending over the wire. Note that it requires SIP to be disabled. (It only works on macOS, obviously)
python3.11 -m venv venv
source ./venv/bin/activate
pip install 'pypush[proxy] @ git+https://github.com/JJTech0130/pypush@initial-rewrite-structure'
sudo apnsproxy
Just refactored the CLI, the command is now just pypush, pypush proxy replaces the apnsproxy command.