pypush icon indicating copy to clipboard operation
pypush copied to clipboard

Rewrite: Initial structure

Open JJTech0130 opened this issue 1 year ago • 6 comments

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 asyncio this time
  • [ ] Work out API for device details and versions

JJTech0130 avatar May 11 '24 16:05 JJTech0130

Maybe this time I should go ahead and implement https://github.com/JJTech0130/pypush/issues/61 right off the bat

JJTech0130 avatar May 11 '24 16:05 JJTech0130

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

JJTech0130 avatar May 11 '24 20:05 JJTech0130

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?

JJTech0130 avatar May 13 '24 01:05 JJTech0130

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 avatar May 13 '24 19:05 JJTech0130

@JJTech0130 Please contact me

BuyAppleidinbulk avatar May 15 '24 12:05 BuyAppleidinbulk

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

JJTech0130 avatar May 15 '24 15:05 JJTech0130

Just refactored the CLI, the command is now just pypush, pypush proxy replaces the apnsproxy command.

JJTech0130 avatar May 16 '24 14:05 JJTech0130