-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: integrate "1st class" plugins into project (#6)
* fix: layout issues * fix: add flake8 to lint dependencies * refactor: move `ape` package to subdir under `src/` * refactor: migrate `ape-accounts` repo to 1st class plugin undo `src/` * feat: add `ape compile` 1st class plugin * fix: isort lint issues * chore: fixup CI calls * test: add test for CLI invocation * chore: fixup testing cli flags * fix: install backported `importlib-metadata` for Python <3.8 * refactor: remove unnecessary default package call * refactor: remove export * fix: need password to delete * test: add fuzz testing, parametrize more * refactor: remove "fuzz" extra as it breaks tests
- Loading branch information
Showing
26 changed files
with
376 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
try: | ||
from importlib.metadata import PackageNotFoundError, version # type: ignore | ||
except ModuleNotFoundError: | ||
from importlib_metadata import PackageNotFoundError, version # type: ignore | ||
|
||
# NOTE: Do this before anything else | ||
from . import _setup # noqa E302 | ||
|
||
try: | ||
__version__ = version(__name__) | ||
except PackageNotFoundError: | ||
# package is not installed | ||
__version__ = "<unknown>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from ape import plugins | ||
|
||
from ._cli import cli | ||
from .accounts import AccountContainer | ||
|
||
|
||
@plugins.register(plugins.CliPlugin) | ||
def register_cli(): | ||
return cli | ||
|
||
|
||
@plugins.register(plugins.AccountPlugin) | ||
def register_accounts(): | ||
return AccountContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import click | ||
|
||
from ape.accounts import accounts | ||
|
||
from .accounts import KeyfileAccount | ||
|
||
|
||
@click.group(short_help="Manage local accounts") | ||
def cli(): | ||
""" | ||
Command-line helper for managing local accounts. You can unlock local accounts from | ||
scripts or the console using the accounts.load() method. | ||
""" | ||
|
||
|
||
# Different name because `list` is a keyword | ||
@cli.command(name="list", short_help="List available accounts") | ||
def _list(): | ||
if len(accounts) == 0: | ||
click.echo("No accounts found.") | ||
return | ||
|
||
elif len(accounts) > 1: | ||
click.echo(f"Found {len(accounts)} accounts:") | ||
|
||
else: | ||
click.echo("Found 1 account:") | ||
|
||
for account in accounts: | ||
alias_display = f" (alias: '{account.alias}')" if account.alias else "" | ||
click.echo(f"{account.address}{alias_display}") | ||
|
||
|
||
@cli.command(short_help="Add a new account with a random private key") | ||
@click.argument("alias") | ||
def generate(alias): | ||
assert alias not in accounts.aliases | ||
a = KeyfileAccount.generate(accounts.path.joinpath(f"{alias}.json")) | ||
click.echo(f"A new account '{a.address}' has been added with the id '{alias}'") | ||
|
||
|
||
# Different name because `import` is a keyword | ||
@cli.command(name="import", short_help="Add a new account by entering a private key") | ||
@click.argument("alias") | ||
def _import(alias): | ||
if alias in accounts.aliases: | ||
click.echo(f"Account with alias '{alias}' already exists") | ||
return | ||
|
||
a = KeyfileAccount.from_key(accounts.DATA_FOLDER.joinpath(f"{alias}.json")) | ||
click.echo(f"A new account '{a.address}' has been added with the id '{alias}'") | ||
|
||
|
||
@cli.command(short_help="Change the password of an existing account") | ||
@click.argument("alias", type=click.Choice(accounts.aliases)) | ||
def change_password(alias): | ||
account = accounts.load(alias) | ||
if not isinstance(account, KeyfileAccount): | ||
click.echo(f"Account '{alias}' cannot change it's password") | ||
return | ||
|
||
account.change_password() | ||
click.echo(f"Password has been changed for account '{alias}'") | ||
|
||
|
||
@cli.command(short_help="Delete an existing account") | ||
@click.argument("alias", type=click.Choice(accounts.aliases)) | ||
def delete(alias): | ||
account = accounts.load(alias) | ||
if not isinstance(account, KeyfileAccount): | ||
click.echo(f"Account '{alias}' is not able to be deleted") | ||
return | ||
|
||
account.delete() | ||
click.echo(f"Account '{alias}' has been deleted") |
Oops, something went wrong.