From 8c8b5abadeebd02a5cb8c81c6e88f406bb2a404d Mon Sep 17 00:00:00 2001 From: antazoey Date: Tue, 7 May 2024 08:42:16 -0600 Subject: [PATCH] refactor: delete deprecated constructs (#2057) --- src/ape/api/projects.py | 25 ++---------------- src/ape/cli/__init__.py | 5 +--- src/ape/cli/choices.py | 13 ---------- src/ape/cli/paramtype.py | 26 ------------------- src/ape/managers/project/dependency.py | 9 +++---- tests/functional/conftest.py | 4 ++- tests/functional/test_config.py | 2 +- tests/functional/test_dependencies.py | 2 +- .../only-dependencies/ape-config.yaml | 3 ++- .../with-dependencies/ape-config.yaml | 6 +++-- 10 files changed, 17 insertions(+), 78 deletions(-) diff --git a/src/ape/api/projects.py b/src/ape/api/projects.py index 8ca51b2fe2..aec943e848 100644 --- a/src/ape/api/projects.py +++ b/src/ape/api/projects.py @@ -343,23 +343,6 @@ class DependencyAPI(ExtraAttributesMixin, BaseInterfaceModel): The version of the dependency. Omit to use the latest. """ - # TODO: Remove in 0.8. - contracts_folder: str = "contracts" - """ - The name of the dependency's ``contracts/`` directory. - This is where ``ape`` will look for source files when compiling - the manifest for this dependency. - - **Deprecated**: Use ``config_override:contracts_folder``. - """ - - # TODO: Remove in 0.8. - exclude: list[str] = [] - """ - A list of glob-patterns for excluding files in dependency projects. - **Deprecated**: Use ``config_override:compile:exclude``. - """ - config_override: dict = {} """ Extra settings to include in the dependency's configuration. @@ -489,6 +472,7 @@ def compile(self, use_cache: bool = True) -> PackageManifest: if "contracts_folder" not in config_data: config_data["contracts_folder"] = contracts_folder + contracts_folder.mkdir(exist_ok=True, parents=True) with self.config_manager.using_project(path, **config_data) as project: manifest.unpack_sources(contracts_folder) compiled_manifest = project.local_project.create_manifest() @@ -538,8 +522,7 @@ def _extract_local_manifest( elif project_path.parent.is_dir(): project_path = project_path.parent - # TODO: In 0.8, delete self.contracts_folder and rely on cfg override. - contracts_folder = self.config_override.get("contracts_folder", self.contracts_folder) + contracts_folder = self.config_override.get("contracts_folder", "contracts") # NOTE: Dependencies are not compiled here. Instead, the sources are packaged # for later usage via imports. For legacy reasons, many dependency-esque projects @@ -583,13 +566,9 @@ def _get_sources(self, project: ProjectAPI) -> list[Path]: extension_pattern = "|".join(escaped_extensions) pattern = rf".*({extension_pattern})" all_sources = get_all_files_in_directory(project.contracts_folder, pattern=pattern) - - # TODO: In 0.8, delete self.exclude and only use config override. exclude = [ - *(self.exclude or []), *(self.config_override.get("compile", {}).get("exclude", []) or []), ] - excluded_files = set() for pattern in set(exclude): excluded_files.update({f for f in project.contracts_folder.glob(pattern)}) diff --git a/src/ape/cli/__init__.py b/src/ape/cli/__init__.py index d712cc3a73..98a3c5f4a9 100644 --- a/src/ape/cli/__init__.py +++ b/src/ape/cli/__init__.py @@ -9,7 +9,6 @@ NetworkChoice, OutputFormat, PromptChoice, - get_user_selected_account, output_format_choice, select_account, ) @@ -27,13 +26,12 @@ skip_confirmation_option, verbosity_option, ) -from ape.cli.paramtype import JSON, AllFilePaths, Path +from ape.cli.paramtype import JSON, Path __all__ = [ "account_option", "AccountAliasPromptChoice", "Alias", - "AllFilePaths", "ape_cli_context", "ApeCliContextObject", "config_override_option", @@ -41,7 +39,6 @@ "contract_file_paths_argument", "contract_option", "existing_alias_argument", - "get_user_selected_account", "incompatible_with", "JSON", "network_option", diff --git a/src/ape/cli/choices.py b/src/ape/cli/choices.py index cdbaa59160..81558be1e3 100644 --- a/src/ape/cli/choices.py +++ b/src/ape/cli/choices.py @@ -1,5 +1,4 @@ import re -import warnings from collections.abc import Callable, Iterator, Sequence from enum import Enum from functools import lru_cache @@ -140,18 +139,6 @@ def select(self) -> str: raise IndexError(f"Choice index '{choice_idx}' out of range.") -def get_user_selected_account( - prompt_message: Optional[str] = None, account_type: _ACCOUNT_TYPE_FILTER = None -) -> AccountAPI: - """ - **DEPRECATED**: Use :meth:`~ape.cli.choices.select_account` instead. - """ - warnings.warn( - "'get_user_selected_account' is deprecated. Use 'select_account'.", DeprecationWarning - ) - return select_account(prompt_message=prompt_message, key=account_type) - - def select_account( prompt_message: Optional[str] = None, key: _ACCOUNT_TYPE_FILTER = None ) -> AccountAPI: diff --git a/src/ape/cli/paramtype.py b/src/ape/cli/paramtype.py index 8ebae94dbc..d58dde71d6 100644 --- a/src/ape/cli/paramtype.py +++ b/src/ape/cli/paramtype.py @@ -1,11 +1,7 @@ import json from pathlib import Path as PathLibPath -from typing import Any, Optional import click -from click import Context, Parameter - -from ape.utils import get_all_files_in_directory class Path(click.Path): @@ -21,28 +17,6 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) -# TODO: Delete for 0.8 (list of lists is weird and we -# are no longer using this). -class AllFilePaths(Path): - """ - Either all the file paths in the given directory, - or a list containing only the given file. - """ - - def convert( # type: ignore[override] - self, value: Any, param: Optional["Parameter"], ctx: Optional["Context"] - ) -> list[PathLibPath]: - path = super().convert(value, param, ctx) - assert isinstance(path, PathLibPath) # For mypy - - if not path.is_file() and path.is_absolute(): - # Don't do absolute non-existent paths. - # Let it resolve elsewhere. - path = PathLibPath(value) - - return get_all_files_in_directory(path) if path.is_dir() else [path] - - class JSON(click.ParamType): """ A type that accepts a raw-JSON str diff --git a/src/ape/managers/project/dependency.py b/src/ape/managers/project/dependency.py index 00a8ee9dce..b6b3aedcad 100644 --- a/src/ape/managers/project/dependency.py +++ b/src/ape/managers/project/dependency.py @@ -299,14 +299,11 @@ class LocalDependency(DependencyAPI): @model_validator(mode="before") @classmethod def validate_contracts_folder(cls, value): - if value.get("contracts_folder") not in (None, "contracts"): + if value.get("config_override", {}).get("contracts_folder"): + # Already set. return value - elif cfg_value := value.get("config_override", {}).get("contracts_folder"): - value["contracts_folder"] = cfg_value - return value - - # If using default value, check if exists + # If using default value, check if exists. local_path_value = value.get("local") or os.getcwd() local_project_path = Path(local_path_value) try_contracts_path = local_project_path / "contracts" diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 38e72cfd16..582265e486 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -340,7 +340,9 @@ def project_with_dependency_config(temp_config): { "local": str(PROJECT_WITH_LONG_CONTRACTS_FOLDER), "name": "testdependency", - "contracts_folder": "source/v0.1", + "config_override": { + "contracts_folder": "source/v0.1", + }, } ] } diff --git a/tests/functional/test_config.py b/tests/functional/test_config.py index a3dc941929..e809ddc8c1 100644 --- a/tests/functional/test_config.py +++ b/tests/functional/test_config.py @@ -162,7 +162,7 @@ def test_network_gas_limit_invalid_numeric_string(config, temp_config): def test_dependencies(project_with_dependency_config, config): assert len(config.dependencies) == 1 assert config.dependencies[0].name == "testdependency" - assert config.dependencies[0].contracts_folder == "source/v0.1" + assert config.dependencies[0].config_override["contracts_folder"] == "source/v0.1" assert config.dependencies[0].local == str(PROJECT_WITH_LONG_CONTRACTS_FOLDER) diff --git a/tests/functional/test_dependencies.py b/tests/functional/test_dependencies.py index 3009767134..a70358d0d0 100644 --- a/tests/functional/test_dependencies.py +++ b/tests/functional/test_dependencies.py @@ -61,7 +61,7 @@ def test_dependency_contracts_folder(config, local_dependency): This test ensures that the contracts folder field is honored, specifically In the case when it contains sub-paths. """ - actual = local_dependency.contracts_folder + actual = local_dependency.config_override["contracts_folder"] assert actual == "source/v0.1" diff --git a/tests/integration/cli/projects/only-dependencies/ape-config.yaml b/tests/integration/cli/projects/only-dependencies/ape-config.yaml index 4818a8ef72..a10d06e4f3 100644 --- a/tests/integration/cli/projects/only-dependencies/ape-config.yaml +++ b/tests/integration/cli/projects/only-dependencies/ape-config.yaml @@ -1,7 +1,8 @@ dependencies: - name: dependency-in-project-only local: ./dependency_in_project_only - contracts_folder: sources + config_override: + contracts_folder: sources compile: # NOTE: this should say `include_dependencies: false` below. diff --git a/tests/integration/cli/projects/with-dependencies/ape-config.yaml b/tests/integration/cli/projects/with-dependencies/ape-config.yaml index 7d44091fad..98aa93ea92 100644 --- a/tests/integration/cli/projects/with-dependencies/ape-config.yaml +++ b/tests/integration/cli/projects/with-dependencies/ape-config.yaml @@ -4,11 +4,13 @@ dependencies: - name: renamed-contracts-folder local: ./renamed_contracts_folder - contracts_folder: sources + config_override: + contracts_folder: sources - name: renamed-complex-contracts-folder local: ./renamed_complex_contracts_folder - contracts_folder: contracts/src/v0.1 + config_override: + contracts_folder: contracts/src/v0.1 - name: containing-sub-dependencies local: ./containing_sub_dependencies