Skip to content

Commit 38c8ab5

Browse files
authored
Move to uv + pyproject.toml (#70)
We've migrated to `uv`/`ruff`/`ty` in basically all our other repos already, so we might as well do so here, too.
1 parent bfc15d8 commit 38c8ab5

19 files changed

Lines changed: 1098 additions & 1047 deletions

.github/workflows/release.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@ jobs:
1515
id-token: write
1616
steps:
1717
- name: "Checkout"
18-
uses: "actions/checkout@v3"
18+
uses: "actions/checkout@v5"
1919
with:
2020
fetch-depth: 10
21-
- name: "Setup Python"
22-
uses: "actions/setup-python@v4"
21+
- name: "Set up Python"
22+
uses: "actions/setup-python@v5"
23+
- name: "Install uv"
24+
uses: "astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57" # v8.0.0
2325
with:
24-
cache: "pipenv"
25-
cache-dependency-path: "sdk/Pipfile.lock"
26-
- name: "Install pipenv"
27-
run: "pip install pipenv wheel"
28-
- name: "Install dependencies"
29-
run: "rm -rf $(pipenv --venv) && pipenv install --dev"
26+
version: "0.11.2"
3027
- name: "Build dist"
31-
run: "pipenv run python setup.py sdist --format=zip"
28+
run: "uv run --frozen python setup.py sdist --format=zip"
3229
- name: Publish package distributions to PyPI
3330
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test.yaml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,30 @@ jobs:
1111
runs-on: "ubuntu-22.04"
1212
strategy:
1313
matrix:
14-
python_version: ["3.8", "3.10"]
14+
python_version: ["3.8", "3.10", "3.12"]
1515
steps:
1616
- name: "Checkout"
17-
uses: "actions/checkout@v3"
17+
uses: "actions/checkout@v5"
1818
with:
1919
fetch-depth: 10
20-
- name: "Setup Python"
21-
uses: "actions/setup-python@v4"
20+
- name: "Set up Python"
21+
uses: "actions/setup-python@v5"
2222
with:
2323
python-version: "${{ matrix.python_version }}"
24-
cache: "pipenv"
25-
cache-dependency-path: "Pipfile.lock"
26-
- name: "Install pipenv"
27-
run: "pip install pipenv wheel"
28-
- name: "Install dependencies"
29-
run: "rm -rf $(pipenv --venv) && pipenv --python ${{ matrix.python_version }} install --dev"
30-
- name: "Run pyre"
31-
run: |
32-
set -o pipefail
33-
pipenv run pyre | tee >(sed 's, ,:,' | awk -F: '{sub(" ", "", $5); print "::error file=" ENVIRON["PWD"] "/" $1 ",line=" $2 ",col=" $3 ",title=" $4 "::" $5}')
24+
- name: "Install uv and set the python version"
25+
uses: "astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57" # v8.0.0
26+
with:
27+
python-version: "${{ matrix.python-version }}"
28+
version: "0.11.2"
29+
working-directory: "lightspark"
30+
- name: "Run ty"
31+
working-directory: "lightspark"
32+
run: "uv run ty check --output-format github ."
3433
- name: "Run pytest"
35-
run: "PYTHONPATH=. pipenv run pytest"
34+
run: "PYTHONPATH=. uv run pytest"
3635
- name: "Run pylint"
37-
run: "PYTHONPATH=. pipenv run pylint --jobs 0 --score n --msg-template='::{category} file={abspath},line={line},col={column},title={msg_id} {symbol}::{msg}' lightspark"
38-
- name: "Run black"
36+
run: "PYTHONPATH=. uv run pylint --jobs 0 --score n --msg-template='::{category} file={abspath},line={line},col={column},title={msg_id} {symbol}::{msg}' lightspark"
37+
- name: "Run ruff format"
3938
run: |
4039
set -o pipefail
41-
pipenv run black --check --diff . | tee >(pipenv run ../scripts/diff2annotation.py)
40+
uv run --frozen ruff format --diff . | tee >(uv run --frozen ./scripts/diff2annotation.py)

.pyre_configuration

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"site_package_search_strategy": "pep561",
33
"source_directories": [
44
"."
5+
],
6+
"ignore_all_errors": [
7+
".venv/**"
58
]
69
}

Pipfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 874 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Lightspark Python SDK provides a convenient way to interact with the Lightsp
66

77
To install the SDK, simply run:
88

9-
```bash
9+
```shell
1010
pip install lightspark
1111
```
1212

@@ -19,16 +19,14 @@ The documentation for this SDK (installation, usage, etc.) is available at https
1919
For your convenience, we included an example that shows you how to use the SDK.
2020
Open the file `example.py` and make sure to update the variables at the top of the page with your information, then run it using pipenv:
2121

22-
```python
23-
pipenv install
24-
pipenv run python -m examples.example
22+
```shell
23+
uv sync
24+
uv run python -m examples.example
2525
```
2626

2727
There are also a few examples of webservers for demonstrating webhooks and LNURLs. These can similarly be run through Flask:
2828

29-
```python
30-
pipenv install -d
31-
pipenv run flask --app examples.flask_lnurl_server run
29+
```shell
30+
uv sync --dev
31+
uv run flask --app examples.flask_lnurl_server run
3232
```
33-
34-
Note that Flask requires Python >= 3.8, so these examples will not work if running Python 3.7.

examples/flask_lnurl_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
##
2424
## export LIGHTSPARK_API_TOKEN_CLIENT_ID=<client_id>
2525
## export LIGHTSPARK_API_TOKEN_CLIENT_SECRET=<client_secret>
26-
API_TOKEN_CLIENT_ID = os.environ.get("LIGHTSPARK_API_TOKEN_CLIENT_ID")
27-
API_TOKEN_CLIENT_SECRET = os.environ.get("LIGHTSPARK_API_TOKEN_CLIENT_SECRET")
26+
API_TOKEN_CLIENT_ID = os.environ["LIGHTSPARK_API_TOKEN_CLIENT_ID"]
27+
API_TOKEN_CLIENT_SECRET = os.environ["LIGHTSPARK_API_TOKEN_CLIENT_SECRET"]
2828
##
2929
## This example also assumes you already know your node UUID. Generally, an LNURL API would serve
3030
## many different usernames while maintaining some internal mapping from username to node UUID. For
3131
## simplicity, this example works with a single username and node UUID.
3232
##
3333
## export LIGHTSPARK_LNURL_NODE_UUID=0187c4d6-704b-f96b-0000-a2e8145bc1f9
34-
LNURL_NODE_UUID = os.environ.get("LIGHTSPARK_LNURL_NODE_UUID")
34+
LNURL_NODE_UUID = os.environ["LIGHTSPARK_LNURL_NODE_UUID"]
3535
LNURL_USERNAME = os.environ.get("LIGHTSPARK_LNURL_USERNAME", "ls_test")
3636
##
3737
## To run the webserver, run this command from the root of the SDK folder:
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
22
"""Sample Lightspark Webhooks Flask App.
33
4-
Install Flask (pip install flask) and then run this like:
4+
Install Flask (uv add flask) and then run this like:
55
6-
pipenv run flask --app examples.flask_remote_signin_server run --port 5001
6+
uv run flask --app examples.flask_remote_signin_server run --port 5001
77
"""
88

99
import os
@@ -13,22 +13,22 @@
1313
app = Flask(__name__)
1414

1515
# Get this from the API Configuration page.
16-
webhook_secret = os.environ.get("RK_WEBHOOK_SECRET")
16+
webhook_secret = os.environ["RK_WEBHOOK_SECRET"]
1717

18-
api_token_client_id = os.environ.get("RK_API_CLIENT_ID")
19-
api_token_client_secret = os.environ.get("RK_API_CLIENT_SECRET")
18+
api_token_client_id = os.environ["RK_API_CLIENT_ID"]
19+
api_token_client_secret = os.environ["RK_API_CLIENT_SECRET"]
2020

21-
master_seed = os.environ.get("RK_MASTER_SEED_HEX")
21+
master_seed = os.environ["RK_MASTER_SEED_HEX"]
2222

2323

2424
@app.route("/ping", methods=["GET"])
25-
def ping():
25+
def ping() -> str:
2626
print("ping")
2727
return "OK"
2828

2929

3030
@app.route("/lightspark-webhook", methods=["POST"])
31-
def webhook():
31+
def webhook() -> str:
3232
client = lightspark.LightsparkSyncClient(
3333
api_token_client_id=api_token_client_id,
3434
api_token_client_secret=api_token_client_secret,
@@ -40,6 +40,6 @@ def webhook():
4040
)
4141

4242
handler.handle_remote_signing_webhook_request(
43-
request.data, request.headers.get(lightspark.SIGNATURE_HEADER), webhook_secret
43+
request.data, request.headers[lightspark.SIGNATURE_HEADER], webhook_secret
4444
)
4545
return "OK"

examples/flask_webhook_server.py

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
from unittest.mock import MagicMock
12
import json
2-
from lightspark.objects.InvoiceData import from_json as InvoiceData_from_json
3-
from lightspark.objects.Node import from_json as Node_from_json
3+
from lightspark.objects import InvoiceData, Node
44

55

66
class TestSerialization:
7-
def test_serialize_deserialize_invoice_data(self):
7+
def test_serialize_deserialize_invoice_data(self) -> None:
8+
requester = MagicMock()
89
serialized = '{"__typename": "InvoiceData", "invoice_data_encoded_payment_request":"lnbcrt34170n1pj5vdn4pp56jhw0672v566u4rvl333v8hwwuvavvu9gx4a2mqag4pkrvm0hwkqhp5xaz278y6cejcvpqnndl4wfq3slgthjduwlfksg778aevn23v2pdscqzpgxqyz5vqsp5ee5jezfvjqvvz7hfwta3ekk8hs6dq36szkgp40qh7twa8upquxlq9qyyssqjg2slc95falxf2t67y0wu2w43qwfcvfflwl8tn4ppqw9tumwqxk36qkfct9p2w8c3yy2ld7c6nacy4ssv2gl6qyqfpmhl4jmarnjf8cpvjlxek","invoice_data_bitcoin_network":"REGTEST","invoice_data_payment_hash":"d4aee7ebca6535ae546cfc63161eee7719d6338541abd56c1d454361b36fbbac","invoice_data_amount":{"currency_amount_original_value":3417,"currency_amount_original_unit":"SATOSHI","currency_amount_preferred_currency_unit":"USD","currency_amount_preferred_currency_value_rounded":118,"currency_amount_preferred_currency_value_approx":118.89352818371607},"invoice_data_created_at":"2023-11-04T12:17:57+00:00","invoice_data_expires_at":"2023-11-05T12:17:57+00:00","invoice_data_memo":null,"invoice_data_destination":{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759+00:00","graph_node_updated_at":"2023-11-04T12:01:04.015414+00:00","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}}'
9-
deserialized = InvoiceData_from_json(None, json.loads(serialized))
10+
deserialized = InvoiceData.from_json(requester, json.loads(serialized))
1011
reserialized = deserialized.to_json()
1112
assert reserialized == json.loads(serialized)
1213

13-
deserialized_again = InvoiceData_from_json(None, reserialized)
14+
deserialized_again = InvoiceData.from_json(requester, reserialized)
1415
assert deserialized_again == deserialized
1516

16-
def test_serialize_deserialize_graph_node(self):
17+
def test_serialize_deserialize_graph_node(self) -> None:
18+
requester = MagicMock()
1719
serialized = '{"graph_node_id":"GraphNode:0189a572-6dba-cf00-0000-ac0908d34ea6","graph_node_created_at":"2023-07-30T06:18:07.162759+00:00","graph_node_updated_at":"2023-11-04T12:01:04.015414+00:00","graph_node_alias":"ls_test_vSViIQitob_SE","graph_node_bitcoin_network":"REGTEST","graph_node_color":"#3399ff","graph_node_conductivity":null,"graph_node_display_name":"ls_test_vSViIQitob_SE","graph_node_public_key":"02253935a5703a6f0429081e08d2defce0faa15f4d75305302284751d53a4e0608", "__typename":"GraphNode"}'
18-
deserialized = Node_from_json(None, json.loads(serialized))
20+
deserialized = Node.from_json(requester, json.loads(serialized))
1921
reserialized = deserialized.to_json()
2022
assert reserialized == json.loads(serialized)
2123

22-
deserialized_again = Node_from_json(None, reserialized)
24+
deserialized_again = Node.from_json(requester, reserialized)
2325
assert deserialized_again == deserialized

0 commit comments

Comments
 (0)