Skip to content

Commit

Permalink
Make dependencies for Ledger support optional (#1474)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
droserasprout and franciszekjob authored Sep 18, 2024
1 parent c461e69 commit 2a84190
Show file tree
Hide file tree
Showing 7 changed files with 615 additions and 512 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger
- name: Check poetry.lock
run: |
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger
# ====================== SETUP DEVNET ====================== #

Expand Down Expand Up @@ -287,7 +287,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger
# ====================== SETUP DEVNET ====================== #

Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger
# ====================== RUN TESTS ====================== #

Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
jobs:
pre_install:
- pip install poetry
- poetry export -f requirements.txt --output requirements.txt --without-hashes --extras docs
- poetry export -f requirements.txt --output requirements.txt --without-hashes -E docs -E ledger

sphinx:
configuration: docs/conf.py
Expand Down
6 changes: 6 additions & 0 deletions docs/api/signer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ KeyPair
LedgerSigner
------------

To use LedgerSigner, you need to install starknetpy with `ledger` extra like this:

.. code-block:: bash
poetry add starknet_py[ledger]
.. py:module:: starknet_py.net.signer.ledger_signer
.. autoclass:: LedgerSigner
Expand Down
4 changes: 2 additions & 2 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Dependencies

.. code-block:: bash
poetry install
poetry install -E ledger
Contracts
^^^^^^^^^
Expand All @@ -64,7 +64,7 @@ Documentation
.. code-block:: bash
# Install additional dependencies for docs
poetry install -E docs
poetry install -E ledger -E docs
# Generate HTML documentation
poe docs_create
Expand Down
1,076 changes: 577 additions & 499 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ furo = { version = "^2024.5.6", optional = true }
pycryptodome = "^3.17"
crypto-cpp-py = "1.4.4"
eth-keyfile = "^0.8.1"
ledgerwallet = "^0.5.0"
bip-utils = "^2.9.3"
ledgerwallet = { version = "^0.5.0", optional = true }
bip-utils = { version = "^2.9.3", optional = true }

[tool.poetry.extras]
docs = ["sphinx", "enum-tools", "furo"]
ledger = ["ledgerwallet", "bip-utils"]

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
Expand Down
26 changes: 22 additions & 4 deletions starknet_py/net/signer/ledger_signer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from typing import List

from bip_utils import Bip32KeyIndex, Bip32Path, Bip32Utils
from ledgerwallet.client import LedgerClient
from typing import TYPE_CHECKING, List

from starknet_py.constants import (
EIP_2645_PATH_LENGTH,
Expand All @@ -17,6 +14,27 @@
from starknet_py.utils.typed_data import TypedData


class LateException:
def __init__(self, exc: Exception):
self.exc = exc

def __getattr__(self, item):
raise self.exc

def __call__(self, *args, **kwargs):
self.__getattr__("exc")


try:
from bip_utils import Bip32KeyIndex, Bip32Path, Bip32Utils
from ledgerwallet.client import LedgerClient
except ImportError as e:
if TYPE_CHECKING:
raise
dummy = LateException(e)
Bip32KeyIndex, Bip32Path, Bip32Utils, LedgerClient = dummy, dummy, dummy, dummy


class LedgerStarknetApp:
def __init__(self):
self.client: LedgerClient = LedgerClient(cla=STARKNET_CLA)
Expand Down

0 comments on commit 2a84190

Please sign in to comment.