diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2de45d1..9cc7305 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml @@ -10,24 +10,24 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.9.1 hooks: - id: black name: black - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.991 + rev: v1.5.1 hooks: - id: mypy additional_dependencies: [types-setuptools, pydantic] - repo: https://github.com/executablebooks/mdformat - rev: 0.7.14 + rev: 0.7.17 hooks: - id: mdformat additional_dependencies: [mdformat-gfm, mdformat-frontmatter] diff --git a/ape_ledger/_cli.py b/ape_ledger/_cli.py index 78f4e63..77fe26f 100644 --- a/ape_ledger/_cli.py +++ b/ape_ledger/_cli.py @@ -72,7 +72,7 @@ def add(cli_ctx, alias, hd_path): """Add an account from your Ledger hardware wallet""" address, account_hd_path = _select_account(hd_path) - container = accounts.containers.get("ledger") + container = accounts.containers["ledger"] container.save_account(alias, address, str(account_hd_path)) cli_ctx.logger.success(f"Account '{address}' successfully added with alias '{alias}'.") @@ -83,7 +83,7 @@ def add(cli_ctx, alias, hd_path): def delete(cli_ctx, alias): """Remove a Ledger account from ape""" - container = accounts.containers.get("ledger") + container = accounts.containers["ledger"] container.delete_account(alias) cli_ctx.logger.success(f"Account '{alias}' has been removed.") @@ -94,7 +94,7 @@ def delete(cli_ctx, alias): def delete_all(cli_ctx, skip_confirmation): """Remove all Ledger accounts from ape""" - container = accounts.containers.get("ledger") + container = accounts.containers["ledger"] ledger_accounts = _get_ledger_accounts() if len(ledger_accounts) == 0: cli_ctx.logger.warning("No accounts found.") diff --git a/ape_ledger/accounts.py b/ape_ledger/accounts.py index 62e8e66..265bab4 100644 --- a/ape_ledger/accounts.py +++ b/ape_ledger/accounts.py @@ -62,9 +62,7 @@ def save_account(self, alias: str, address: str, hd_path: str): def delete_account(self, alias: str): path = self.data_folder.joinpath(f"{alias}.json") - - if path.exists(): - path.unlink() + path.unlink(missing_ok=True) def _echo_object_to_sign(obj: Union[TransactionAPI, SignableMessage]): diff --git a/ape_ledger/choices.py b/ape_ledger/choices.py index 32d5adb..ff0076f 100644 --- a/ape_ledger/choices.py +++ b/ape_ledger/choices.py @@ -27,7 +27,7 @@ def __init__( self._hd_root_path = hd_path self._index_offset = index_offset self._page_size = page_size - self._choice_index = None + self._choice_index: Optional[int] = None # Must call ``_load_choices()`` to set address choices super().__init__([]) @@ -54,7 +54,8 @@ def convert( return None address = super().convert(value, param, ctx) - self._choice_index = self.choices.index(address) + address_index = self.choices.index(address) + self._choice_index = self._choice_index if address_index is None else address_index return address def get_user_selected_account(self) -> Tuple[str, HDAccountPath]: diff --git a/setup.py b/setup.py index 9af311e..6c7b262 100644 --- a/setup.py +++ b/setup.py @@ -12,14 +12,15 @@ "hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer ], "lint": [ - "black>=23.3.0,<24", # auto-formatter and linter - "mypy>=0.991,<1", # Static type analyzer + "black>=23.9.1,<24", # auto-formatter and linter + "mypy>=1.5.1,<2", # Static type analyzer "types-setuptools", # Needed due to mypy typeshed - "flake8>=6.0.0,<7", # Style linter + "flake8>=6.1.0,<7", # Style linter "isort>=5.10.1,<6", # Import sorting linter - "mdformat>=0.7.16", # Auto-formatter for markdown + "mdformat>=0.7.17", # Auto-formatter for markdown "mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown "mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates + "pydantic<2.0", # Needed for successful type check. TODO: Remove after full v2 support. ], "release": [ # `release` GitHub Action job uses this "setuptools", # Installation tool diff --git a/tests/test_integration.py b/tests/test_integration.py index ff5f968..5338215 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -77,7 +77,7 @@ def test_add(runner, assert_account, address, alias, choices, hd_path): choices(address, 2) result = runner.invoke(cli, ["ledger", "add", alias]) assert result.exit_code == 0, result.output - assert f"SUCCESS: Account '{address}' successfully added with alias '{alias}'." in result.output + assert f"Account '{address}' successfully added with alias '{alias}'." in result.output expected_path = container.data_folder.joinpath(f"{alias}.json") expected_hd_path = "m/44'/60'/2'/0/0" @@ -93,7 +93,7 @@ def test_add_when_hd_path_specified(runner, alias, address, hd_path, assert_acco ["ledger", "add", alias, "--hd-path", test_hd_path], ) assert result.exit_code == 0, result.output - assert f"SUCCESS: Account '{address}' successfully added with alias '{alias}'." in result.output + assert f"Account '{address}' successfully added with alias '{alias}'." in result.output expected_path = container.data_folder.joinpath(f"{alias}.json") expected_hd_path = "m/44'/60'/0'/2" @@ -117,10 +117,11 @@ def test_add_alias_already_exists(runner, existing_account, choices, address, al def test_delete(runner, existing_account, alias): result = runner.invoke(cli, ["ledger", "delete", alias]) assert result.exit_code == 0, result.output - assert f"SUCCESS: Account '{alias}' has been removed" in result.output + assert f"Account '{alias}' has been removed" in result.output def test_delete_account_not_exists(runner, alias): - result = runner.invoke(cli, ["ledger", "delete", alias]) + not_alias = f"{alias}TYPO" + result = runner.invoke(cli, ["ledger", "delete", not_alias]) assert result.exit_code == 2 - assert f"'{alias}' is not one of" in result.output + assert f"'{not_alias}'" in result.output