From a27b232b11ca5d074b7921fde20c6ea9cca9d3a1 Mon Sep 17 00:00:00 2001 From: antazoey Date: Wed, 1 May 2024 14:24:07 -0600 Subject: [PATCH] fix: random fixes from last couple PRs (#2046) --- docs/userguides/clis.md | 2 +- docs/userguides/dependencies.md | 42 ++++++++++++++++++--------------- src/ape/utils/__init__.py | 2 ++ src/ape/utils/misc.py | 13 ++++++++++ src/ape_compile/__init__.py | 20 ++++------------ 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/docs/userguides/clis.md b/docs/userguides/clis.md index 6df5e1bb03..6c6fa54113 100644 --- a/docs/userguides/clis.md +++ b/docs/userguides/clis.md @@ -218,7 +218,7 @@ my_accounts = [accounts.load("me"), accounts.load("me2")] selected_account = get_user_selected_account(account_type=my_accounts) ``` -# Contract File Paths +## Contract File Paths Does your CLI interact with contract source files? (Think `ape compile`). diff --git a/docs/userguides/dependencies.md b/docs/userguides/dependencies.md index 1efea1e45f..709c7a38d8 100644 --- a/docs/userguides/dependencies.md +++ b/docs/userguides/dependencies.md @@ -53,7 +53,6 @@ You can use already-downloaded projects as dependencies by referencing them as l dependencies: - name: MyDependency local: local/path/to/MyDependency - contracts_folder: src/contracts ``` This is helpful when: @@ -206,42 +205,47 @@ ape compile --include-dependencies The following guidelines are applicable to **ALL** dependency types. -### Custom Contracts Folder +### Config Override -You can set the name of the dependency's contracts folder, e.g.: +To use any extra config item for a dependency, such as configurations for compilers needed during compiling, use the `config_override` setting: ```yaml dependencies: - - name: DappToolsERC20 - github: dapphub/erc20 - ref: dappnix - contracts_folder: src + - name: dependency + github: org-name/dependency-project-name + config_override: + solidity: + evm_version: paris ``` -### File Exclusions +This is the same as if these values were in an `ape-config.yaml` file in the project directly. + +### Custom Contracts Folder -To ignore files from a dependency project, use the `exclude` setting to specify glob patterns: +You can set the name of the dependency's contracts folder using the `config_override` key, e.g.: ```yaml dependencies: - - name: dependency-project-name - github: org-name/dependency-project-name - exclude: - - package.json # Ignore package.json files. - - mocks/**/* # Ignore all files in the 'mocks' directory + - name: DappToolsERC20 + github: dapphub/erc20 + ref: dappnix + config_override: + contracts_folder: src ``` -### Config Override +### File Exclusions -To use any extra config item for a dependency, such as configurations for compilers needed during compiling, use the `config_override` setting: +To ignore files from a dependency project, use the `exclude` setting in the `config_override:compile` section to specify glob patterns: ```yaml dependencies: - - name: dependency + - name: dependency-project-name github: org-name/dependency-project-name config_override: - solidity: - evm_version: paris + compile: + exclude: + - package.json # Ignore package.json files. + - mocks/**/* # Ignore all files in the 'mocks' directory ``` ### Solidity Remappings diff --git a/src/ape/utils/__init__.py b/src/ape/utils/__init__.py index f8782b556a..03905df0fa 100644 --- a/src/ape/utils/__init__.py +++ b/src/ape/utils/__init__.py @@ -24,6 +24,7 @@ DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT, DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT, EMPTY_BYTES32, + SOURCE_EXCLUDE_PATTERNS, USER_AGENT, ZERO_ADDRESS, add_padding_to_strings, @@ -110,6 +111,7 @@ "returns_array", "run_until_complete", "singledispatchmethod", + "SOURCE_EXCLUDE_PATTERNS", "spawn", "stream_response", "Struct", diff --git a/src/ape/utils/misc.py b/src/ape/utils/misc.py index 181c0d645e..556e4b6d04 100644 --- a/src/ape/utils/misc.py +++ b/src/ape/utils/misc.py @@ -32,6 +32,19 @@ DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER = 1.4 DEFAULT_TRANSACTION_TYPE = 0 DEFAULT_MAX_RETRIES_TX = 20 +SOURCE_EXCLUDE_PATTERNS = ( + "*package.json", + "*package-lock.json", + "*tsconfig.json", + "*.md", + "*.rst", + "*.txt", + "*.py[a-zA-Z]?", + "*.html", + "*.css", + "*.adoc", +) + _python_version = ( f"{sys.version_info.major}.{sys.version_info.minor}" diff --git a/src/ape_compile/__init__.py b/src/ape_compile/__init__.py index 48264bb66f..a7633c5fdd 100644 --- a/src/ape_compile/__init__.py +++ b/src/ape_compile/__init__.py @@ -1,24 +1,13 @@ from pathlib import Path -from typing import List, Optional +from typing import Optional, Set from pydantic import field_validator, model_validator from ape import plugins from ape.api import PluginConfig +from ape.utils.misc import SOURCE_EXCLUDE_PATTERNS DEFAULT_CACHE_FOLDER_NAME = ".cache" # default relative to contracts/ -EXCLUDE_PATTERNS = [ - "*package.json", - "*package-lock.json", - "*tsconfig.json", - "*.md", - "*.rst", - "*.txt", - "*.py[a-zA-Z]?", - "*.html", - "*.css", - "*.adoc", -] class Config(PluginConfig): @@ -33,7 +22,7 @@ class Config(PluginConfig): should configure ``include_dependencies`` to be ``True``. """ - exclude: List[str] = [] + exclude: Set[str] = set() """ Source exclusion globs across all file types. """ @@ -91,8 +80,7 @@ def validate_cache_folder(self): @field_validator("exclude", mode="before") @classmethod def validate_exclude(cls, value): - excl = [*(value or []), *EXCLUDE_PATTERNS] - return list(set(excl)) + return {*(value or []), *SOURCE_EXCLUDE_PATTERNS} @plugins.register(plugins.Config)