From 4de7be0cde94091e847f58b2cb1e6b7011cec8ff Mon Sep 17 00:00:00 2001 From: antazoey Date: Wed, 8 May 2024 11:02:31 -0600 Subject: [PATCH] refactor: misc, small changes (#2074) --- src/ape/contracts/base.py | 4 ---- src/ape/exceptions.py | 1 - src/ape/managers/converters.py | 4 ++-- src/ape/utils/__init__.py | 4 ++++ src/ape/utils/misc.py | 2 +- src/ape/utils/os.py | 9 ++++----- src/ape_ethereum/ecosystem.py | 18 ++++++++++++++++++ src/ape_ethereum/transactions.py | 1 - src/ape_pm/compiler.py | 1 - tests/integration/cli/test_init.py | 4 +--- 10 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/ape/contracts/base.py b/src/ape/contracts/base.py index 85617aa392..cdb50afc20 100644 --- a/src/ape/contracts/base.py +++ b/src/ape/contracts/base.py @@ -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 diff --git a/src/ape/exceptions.py b/src/ape/exceptions.py index 860aa57cad..3e0e995486 100644 --- a/src/ape/exceptions.py +++ b/src/ape/exceptions.py @@ -380,7 +380,6 @@ def __init__( elif ecosystem: message = f"'{ecosystem}' has no networks." - else: message = "No networks found." diff --git a/src/ape/managers/converters.py b/src/ape/managers/converters.py index 4a1f1aa407..7e99fb3ce2 100644 --- a/src/ape/managers/converters.py +++ b/src/ape/managers/converters.py @@ -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: @@ -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 = " " diff --git a/src/ape/utils/__init__.py b/src/ape/utils/__init__.py index b76dbe5ab7..2ac3db2af3 100644 --- a/src/ape/utils/__init__.py +++ b/src/ape/utils/__init__.py @@ -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 ( @@ -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, @@ -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", @@ -108,6 +111,7 @@ "LogInputABICollection", "ManagerAccessMixin", "nonreentrant", + "only_raise_attribute_error", "parse_coverage_tables", "parse_gas_table", "raises_not_implemented", diff --git a/src/ape/utils/misc.py b/src/ape/utils/misc.py index 4d47d6ae64..977ce12825 100644 --- a/src/ape/utils/misc.py +++ b/src/ape/utils/misc.py @@ -40,7 +40,7 @@ "*.md", "*.rst", "*.txt", - "*.py[a-zA-Z]?", + "*.py*", "*.html", "*.css", "*.adoc", diff --git a/src/ape/utils/os.py b/src/ape/utils/os.py index 33be9ab724..ff0182b81f 100644 --- a/src/ape/utils/os.py +++ b/src/ape/utils/os.py @@ -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:: @@ -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()] diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index 778b587da3..d9b9d21b01 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -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" """ diff --git a/src/ape_ethereum/transactions.py b/src/ape_ethereum/transactions.py index 2c81d5ae91..15727c5b8d 100644 --- a/src/ape_ethereum/transactions.py +++ b/src/ape_ethereum/transactions.py @@ -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([]) diff --git a/src/ape_pm/compiler.py b/src/ape_pm/compiler.py index 2c4ed22472..da56cbbfc8 100644 --- a/src/ape_pm/compiler.py +++ b/src/ape_pm/compiler.py @@ -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 diff --git a/tests/integration/cli/test_init.py b/tests/integration/cli/test_init.py index e47d9511a3..2d3cd0baa4 100644 --- a/tests/integration/cli/test_init.py +++ b/tests/integration/cli/test_init.py @@ -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"]))