Skip to content

Commit

Permalink
Merge pull request #53 from mikeshultz/feat/repackage
Browse files Browse the repository at this point in the history
feat: repackage python package
  • Loading branch information
mikeshultz authored Oct 20, 2024
2 parents a82f378 + 147095c commit f41cc74
Show file tree
Hide file tree
Showing 33 changed files with 621 additions and 514 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install -e .[dev]
python-version: "3.12"
- run: pip install .[dev]
- run: pytest

test-release:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: "3.12"

- name: Install dependencies
run: pip install -e .[dev]
run: pip install .[dev]

- name: Build dist
run: python setup.py sdist bdist_wheel
Expand All @@ -40,14 +40,14 @@ jobs:
needs: test-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: "3.12"

- name: Install dependencies
run: pip install -e .[dev]
run: pip install .[dev]

- name: Build dist
run: python setup.py sdist bdist_wheel
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e .[dev]
- run: black --check .
- run: isort --profile black --check .
- run: autoflake -cr .
python-version: "3.12"
- run: pip install .[dev]
- run: ruff check
- run: ruff format --check
- run: pyright

test:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e .[dev]
- run: pip install .[dev]
- run: pytest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ dmypy.json
# Pyre type checker
.pyre/

*.sublime-*
*.sublime-*
_local/
6 changes: 1 addition & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ Make sure to lint your work:

## Release

1) Bump version (`bump2version patch`). This will update the version in source and make a commit and version tag. Don't forget to push your tags: `git push --follow-tags`.
2) Merge branch into `master`
3) Create GitHub release with tag created by bump2version and release will happen automatically

**TIP**: Instead of `--follow-tags`, you can configure git to always do this on push: `git config --global push.followTags true`
To release this package, create a new GitHub release and publish it.
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
"""Configuration file for the Sphinx documentation builder."""

# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
Expand Down Expand Up @@ -207,11 +205,13 @@


def skip(app, what, name, obj, would_skip, options):
"""Skip __init__ methods with no docstring."""
if name == "__init__":
# Skip if there's no docstring
return getattr(obj, "__doc__", None) is None
return would_skip


def setup(app):
"""Setup the Sphinx app."""
app.connect("autodoc-skip-member", skip)
14 changes: 9 additions & 5 deletions ledgereth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8:noqa
from ledgereth._meta import author, email, version
from importlib.metadata import metadata
from ledgereth.accounts import find_account, get_account_by_path, get_accounts
from ledgereth.messages import sign_message, sign_typed_data_draft
from ledgereth.objects import (
Expand All @@ -12,9 +12,13 @@
)
from ledgereth.transactions import create_transaction, sign_transaction

meta = metadata("ledgereth")

__all__ = [
"Transaction",
"Type1Transaction" "Type2Transaction" "SignedTransaction",
"Type1Transaction",
"Type2Transaction",
"SignedTransaction",
"SignedType1Transaction",
"SignedType2Transaction",
"create_transaction",
Expand All @@ -25,6 +29,6 @@
"sign_transaction",
"sign_typed_data_draft",
]
__version__ = version
__author__ = author
__email__ = email
__version__ = meta["Version"]
__author__ = meta["Author-email"].split("<")[0].strip()
__email__ = meta["Author-email"]
22 changes: 21 additions & 1 deletion ledgereth/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Main entry point for the CLI."""

import argparse
import sys
from enum import IntEnum

from eth_utils import decode_hex, encode_hex
from eth_utils.hexadecimal import decode_hex

from ledgereth import (
create_transaction,
Expand All @@ -16,12 +18,15 @@


class ExitCodes(IntEnum):
"""Unix exit codes for the CLI."""

SUCCESS = 0
GENERAL_ERROR = 1
INVALID_ARGUMENT = 2


def get_args(argv):
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Do some ledger ops")
parser.add_argument(
"-d",
Expand Down Expand Up @@ -158,6 +163,7 @@ def get_args(argv):


def print_accounts(dongle, args):
"""Print accounts from the Ledger."""
if args.path:
account = get_account_by_path(args.path, dongle)
print(f"Account {account.path} {account.address}")
Expand All @@ -168,6 +174,7 @@ def print_accounts(dongle, args):


def send_value(dongle, args):
"""Send a value transaction from a Ledger account."""
print(f"Sending {args.wei} ETH from {args.from_address} to {args.to_address}")

account = find_account(args.from_address, dongle)
Expand Down Expand Up @@ -201,20 +208,32 @@ def send_value(dongle, args):


def sign_text_message(dongle, args):
"""Sign a text message with a Ledger account."""
print(f'Signing "{args.message}" with {args.account_address}')

account = find_account(args.account_address, dongle)

if not account:
print("Account not found on device", file=sys.stderr)
return

signed = sign_message(args.message, account.path)

print(f"Signature: {signed.signature}")


def sign_typed_data(dongle, args):
"""Sign a typed data message with a Ledger account."""
print(f"Signing typed data with account {args.account_address}")
print(f"Domain hash: {args.domain_hash}")
print(f"Message hash: {args.message_hash}")

account = find_account(args.account_address, dongle)

if not account:
print("Account not found on device", file=sys.stderr)
return

signed = sign_typed_data_draft(
decode_hex(args.domain_hash), decode_hex(args.message_hash), account.path
)
Expand All @@ -231,6 +250,7 @@ def sign_typed_data(dongle, args):


def main(argv=sys.argv[1:]):
"""Main entry point for the CLI."""
args = get_args(argv)
command = args.command

Expand Down
3 changes: 0 additions & 3 deletions ledgereth/_meta.py

This file was deleted.

23 changes: 12 additions & 11 deletions ledgereth/accounts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import List, Optional
"""Account management functions for Ledger devices."""

from eth_utils import to_checksum_address
from __future__ import annotations

from eth_utils.address import to_checksum_address

from ledgereth.comms import (
Dongle,
Expand All @@ -18,9 +20,9 @@


def get_account_by_path(
path_string: str, dongle: Optional[Dongle] = None
path_string: str, dongle: Dongle | None = None
) -> LedgerAccount:
"""Return an account for a specific `BIP-44`_ derivation path
"""Return an account for a specific `BIP-44`_ derivation path.
:param path_string: (:code:`str`) - HID derivation path for the account to
sign with.
Expand All @@ -40,9 +42,9 @@ def get_account_by_path(


def get_accounts(
dongle: Optional[Dongle] = None, count: int = DEFAULT_ACCOUNTS_FETCH
) -> List[LedgerAccount]:
"""Return available accounts
dongle: Dongle | None = None, count: int = DEFAULT_ACCOUNTS_FETCH
) -> list[LedgerAccount]:
"""Return available accounts.
:param dongle: (:class:`ledgerblue.Dongle.Dongle`) - The Dongle instance to
use to communicate with the Ledger device
Expand All @@ -65,9 +67,9 @@ def get_accounts(


def find_account(
address: str, dongle: Optional[Dongle] = None, count: int = MAX_ACCOUNTS_FETCH
) -> Optional[LedgerAccount]:
"""Find an account by address
address: str, dongle: Dongle | None = None, count: int = MAX_ACCOUNTS_FETCH
) -> LedgerAccount | None:
"""Find an account by address.
:param address: (:class:`str`) - An address to look up
:param dongle: (:class:`ledgerblue.Dongle.Dongle`) - The Dongle instance to
Expand All @@ -76,7 +78,6 @@ def find_account(
:return: :class:`ledgereth.objects.LedgerAccount` instance if found on the
Ledger
"""

address = to_checksum_address(address)

for account in get_accounts(dongle, count):
Expand Down
Loading

0 comments on commit f41cc74

Please sign in to comment.