Skip to content

Commit 2a84190

Browse files
Make dependencies for Ledger support optional (#1474)
* Make dependencies for Ledger support optional * Cleanup typehints * Fix checks.yml workflow * Fix code block in docs * checks.yml: SETUP section, python setup, consistent matrix use * Skip [ledger] for doc tests * Revert unrelated changes --------- Co-authored-by: Franciszek Job <[email protected]>
1 parent c461e69 commit 2a84190

File tree

7 files changed

+615
-512
lines changed

7 files changed

+615
-512
lines changed

.github/workflows/checks.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Install dependencies
4343
run: |
44-
poetry install
44+
poetry install -E ledger
4545
4646
- name: Check poetry.lock
4747
run: |
@@ -175,7 +175,7 @@ jobs:
175175

176176
- name: Install dependencies
177177
run: |
178-
poetry install
178+
poetry install -E ledger
179179
180180
# ====================== SETUP DEVNET ====================== #
181181

@@ -287,7 +287,7 @@ jobs:
287287

288288
- name: Install dependencies
289289
run: |
290-
poetry install
290+
poetry install -E ledger
291291
292292
# ====================== SETUP DEVNET ====================== #
293293

@@ -374,7 +374,7 @@ jobs:
374374

375375
- name: Install dependencies
376376
run: |
377-
poetry install
377+
poetry install -E ledger
378378
379379
# ====================== RUN TESTS ====================== #
380380

.readthedocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build:
99
jobs:
1010
pre_install:
1111
- pip install poetry
12-
- poetry export -f requirements.txt --output requirements.txt --without-hashes --extras docs
12+
- poetry export -f requirements.txt --output requirements.txt --without-hashes -E docs -E ledger
1313

1414
sphinx:
1515
configuration: docs/conf.py

docs/api/signer.rst

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ KeyPair
3636
LedgerSigner
3737
------------
3838

39+
To use LedgerSigner, you need to install starknetpy with `ledger` extra like this:
40+
41+
.. code-block:: bash
42+
43+
poetry add starknet_py[ledger]
44+
3945
.. py:module:: starknet_py.net.signer.ledger_signer
4046
4147
.. autoclass:: LedgerSigner

docs/development.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Dependencies
3737

3838
.. code-block:: bash
3939
40-
poetry install
40+
poetry install -E ledger
4141
4242
Contracts
4343
^^^^^^^^^
@@ -64,7 +64,7 @@ Documentation
6464
.. code-block:: bash
6565
6666
# Install additional dependencies for docs
67-
poetry install -E docs
67+
poetry install -E ledger -E docs
6868
6969
# Generate HTML documentation
7070
poe docs_create

poetry.lock

+577-499
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ furo = { version = "^2024.5.6", optional = true }
2929
pycryptodome = "^3.17"
3030
crypto-cpp-py = "1.4.4"
3131
eth-keyfile = "^0.8.1"
32-
ledgerwallet = "^0.5.0"
33-
bip-utils = "^2.9.3"
32+
ledgerwallet = { version = "^0.5.0", optional = true }
33+
bip-utils = { version = "^2.9.3", optional = true }
3434

3535
[tool.poetry.extras]
3636
docs = ["sphinx", "enum-tools", "furo"]
37+
ledger = ["ledgerwallet", "bip-utils"]
3738

3839
[tool.poetry.group.dev.dependencies]
3940
pytest = "^8.2.2"

starknet_py/net/signer/ledger_signer.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from typing import List
2-
3-
from bip_utils import Bip32KeyIndex, Bip32Path, Bip32Utils
4-
from ledgerwallet.client import LedgerClient
1+
from typing import TYPE_CHECKING, List
52

63
from starknet_py.constants import (
74
EIP_2645_PATH_LENGTH,
@@ -17,6 +14,27 @@
1714
from starknet_py.utils.typed_data import TypedData
1815

1916

17+
class LateException:
18+
def __init__(self, exc: Exception):
19+
self.exc = exc
20+
21+
def __getattr__(self, item):
22+
raise self.exc
23+
24+
def __call__(self, *args, **kwargs):
25+
self.__getattr__("exc")
26+
27+
28+
try:
29+
from bip_utils import Bip32KeyIndex, Bip32Path, Bip32Utils
30+
from ledgerwallet.client import LedgerClient
31+
except ImportError as e:
32+
if TYPE_CHECKING:
33+
raise
34+
dummy = LateException(e)
35+
Bip32KeyIndex, Bip32Path, Bip32Utils, LedgerClient = dummy, dummy, dummy, dummy
36+
37+
2038
class LedgerStarknetApp:
2139
def __init__(self):
2240
self.client: LedgerClient = LedgerClient(cla=STARKNET_CLA)

0 commit comments

Comments
 (0)