Skip to content

Commit

Permalink
fix: ignore signHash warning and packages.select warning (ApeWorX#2040)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Apr 30, 2024
1 parent cc05f51 commit c125158
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"pytest-xdist>=3.5.0,<4", # Multi-process runner
"pytest-cov>=4.0.0,<5", # Coverage analyzer plugin
"pytest-mock", # For creating mocks
"pytest-timeout~=2.2.0",
"pytest-timeout>=2.2.0,<3", # For avoiding timing out during tests
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
"hypothesis-jsonschema==0.19.0", # JSON Schema fuzzer extension
],
Expand Down
16 changes: 10 additions & 6 deletions src/ape/_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import difflib
import re
import sys
import warnings
from gettext import gettext
from importlib.metadata import entry_points
from pathlib import Path
Expand Down Expand Up @@ -125,13 +126,16 @@ def commands(self) -> Dict:
if self._commands:
return self._commands

# Update when dropping Python 3.9 support.
_entry_points = entry_points()
eps: Iterable = (
_entry_points.get(self._CLI_GROUP_NAME, [])
if isinstance(_entry_points, dict)
else entry_points(group=self._CLI_GROUP_NAME)
)
eps: Iterable
if select_fn := getattr(_entry_points, "select", None):
# NOTE: Using getattr because mypy.
eps = select_fn(group=self._CLI_GROUP_NAME)
else:
# Python 3.9. Can remove once we drop support.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
eps = _entry_points.get(self._CLI_GROUP_NAME, [])

self._commands = {clean_plugin_name(cmd.name): cmd.load for cmd in eps}
return self._commands
Expand Down
7 changes: 6 additions & 1 deletion src/ape_accounts/accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import warnings
from os import environ
from pathlib import Path
from typing import Any, Dict, Iterator, Optional, Tuple
Expand Down Expand Up @@ -238,7 +239,11 @@ def sign_raw_msghash(self, msghash: HexBytes) -> Optional[MessageSignature]:
if not click.confirm("Please confirm you wish to sign using `EthAccount.signHash`"):
return None

signed_msg = EthAccount.signHash(msghash, self.__key)
# Ignoring misleading deprecated warning from web3.py.
# Also, we have already warned the user about the safety.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
signed_msg = EthAccount.signHash(msghash, self.__key)

return MessageSignature(
v=signed_msg.v,
Expand Down
5 changes: 4 additions & 1 deletion src/ape_test/accounts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any, Iterator, List, Optional

from eip712.messages import EIP712Message
Expand Down Expand Up @@ -145,7 +146,9 @@ def sign_transaction(self, txn: TransactionAPI, **signer_options) -> Optional[Tr
return txn

def sign_raw_msghash(self, msghash: HexBytes) -> MessageSignature:
signed_msg = EthAccount.signHash(msghash, self.private_key)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
signed_msg = EthAccount.signHash(msghash, self.private_key)

return MessageSignature(
v=signed_msg.v,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def test_sources(project_with_source_files_contract):

def test_contracts_folder(project, config):
# Relaxed to handle xdist resource sharing.
assert project.contracts_folder.name == "contracts"
assert project.contracts_folder.name in ("contracts", "src")

# Show that even when None in the config, it won't be None here.
config.contracts_folder = None
Expand Down

0 comments on commit c125158

Please sign in to comment.