Skip to content

Commit

Permalink
refactor: misc, small changes (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored May 8, 2024
1 parent fd38225 commit 4de7be0
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
4 changes: 0 additions & 4 deletions src/ape/contracts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,6 @@ def source_path(self) -> Optional[Path]:
"""
Returns the path to the local contract if determined that this container
belongs to the active project by cross checking source_id.
WARN: The will return a path if the contract has the same
source ID as one in the current project. That does not necessarily mean
they are the same contract, however.
"""
if not (source_id := self.contract_type.source_id):
return None
Expand Down
1 change: 0 additions & 1 deletion src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def __init__(

elif ecosystem:
message = f"'{ecosystem}' has no networks."

else:
message = "No networks found."

Expand Down
4 changes: 2 additions & 2 deletions src/ape/managers/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
from .base import BaseManager


# NOTE: This utility converter ensures that all bytes args can accept hex too
class HexConverter(ConverterAPI):
"""
A converter that converts ``str`` to ``HexBytes``.
NOTE: This utility converter ensures that all bytes args can accept hex too
"""

def is_convertible(self, value: Any) -> bool:
Expand Down Expand Up @@ -369,7 +369,7 @@ def convert(self, value: Any, type: Union[Type, Tuple, List]) -> Any:
return converter.convert(value)
except Exception as err:
try:
error_value = f" '{value}' "
error_value = f" '{value}' (type={type(value)}) "
except Exception:
error_value = " "

Expand Down
4 changes: 4 additions & 0 deletions src/ape/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ExtraModelAttributes,
ManagerAccessMixin,
injected_before_use,
only_raise_attribute_error,
)
from ape.utils.github import GithubClient, github_client
from ape.utils.misc import (
Expand Down Expand Up @@ -50,6 +51,7 @@
create_tempdir,
expand_environment_variables,
get_all_files_in_directory,
get_full_extension,
get_relative_path,
run_in_tempdir,
use_temp_sys_path,
Expand Down Expand Up @@ -94,6 +96,7 @@
"generate_dev_accounts",
"get_all_files_in_directory",
"get_current_timestamp_ms",
"get_full_extension",
"pragma_str_to_specifier_set",
"injected_before_use",
"is_array",
Expand All @@ -108,6 +111,7 @@
"LogInputABICollection",
"ManagerAccessMixin",
"nonreentrant",
"only_raise_attribute_error",
"parse_coverage_tables",
"parse_gas_table",
"raises_not_implemented",
Expand Down
2 changes: 1 addition & 1 deletion src/ape/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"*.md",
"*.rst",
"*.txt",
"*.py[a-zA-Z]?",
"*.py*",
"*.html",
"*.css",
"*.adoc",
Expand Down
9 changes: 4 additions & 5 deletions src/ape/utils/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_all_files_in_directory(
path: Path, pattern: Optional[Union[Pattern, str]] = None
) -> List[Path]:
"""
Returns all the files in a directory structure.
Returns all the files in a directory structure (recursive).
For example, given a directory structure like::
Expand All @@ -81,11 +81,10 @@ def get_all_files_in_directory(
Returns:
List[pathlib.Path]: A list of files in the given directory.
"""
if not path.exists():
return []

elif path.is_file():
if path.is_file():
return [path]
elif not path.is_dir():
return []

# is dir
all_files = [p for p in list(path.rglob("*.*")) if p.is_file()]
Expand Down
18 changes: 18 additions & 0 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,27 @@ class NetworkConfig(PluginConfig):
"""

block_time: int = 0
"""
Approximate amount of time for a block to be
added to the network.
"""

transaction_acceptance_timeout: int = DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT
"""
The amount tof time before failing when sending a
transaction and it leaving the mempool.
"""

default_transaction_type: TransactionType = TransactionType.DYNAMIC
"""
The default type of transaction to use.
"""

max_receipt_retries: int = DEFAULT_MAX_RETRIES_TX
"""
Maximum number of retries when getting a receipt
from a transaction before failing.
"""

gas_limit: GasLimit = "auto"
"""
Expand Down
1 change: 0 additions & 1 deletion src/ape_ethereum/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def source_traceback(self) -> SourceTraceback:
# Failing to get a traceback should not halt an Ape application.
# Sometimes, a node crashes and we are left with nothing.
logger.error(f"Problem retrieving traceback: {err}")
pass

return SourceTraceback.model_validate([])

Expand Down
1 change: 0 additions & 1 deletion src/ape_pm/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def compile_code(
):
# Raw contract type JSON or raw compiler output.
contract_type_data = {**data, **kwargs}

if (
"deploymentBytecode" not in contract_type_data
or "runtimeBytecode" not in contract_type_data
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def test_fail_all_files_and_folders_exist(ape_cli, runner, project):
for folder_name in ["contracts", "tests", "scripts"]:
# Create target Directory
folder = project_folder_path / folder_name
if folder.exists():
pass
else:
if not folder.exists():
folder.mkdir(exist_ok=False)

result = runner.invoke(ape_cli, ["init"], input="\n".join(["init_fail"]))
Expand Down

0 comments on commit 4de7be0

Please sign in to comment.