Skip to content

Commit

Permalink
refactor: delete deprecated constructs (#2057)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed May 7, 2024
1 parent a119fdb commit 8c8b5ab
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 78 deletions.
25 changes: 2 additions & 23 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)})
Expand Down
5 changes: 1 addition & 4 deletions src/ape/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
NetworkChoice,
OutputFormat,
PromptChoice,
get_user_selected_account,
output_format_choice,
select_account,
)
Expand All @@ -27,21 +26,19 @@
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",
"ConnectedProviderCommand",
"contract_file_paths_argument",
"contract_option",
"existing_alias_argument",
"get_user_selected_account",
"incompatible_with",
"JSON",
"network_option",
Expand Down
13 changes: 0 additions & 13 deletions src/ape/cli/choices.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import warnings
from collections.abc import Callable, Iterator, Sequence
from enum import Enum
from functools import lru_cache
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 0 additions & 26 deletions src/ape/cli/paramtype.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/ape/managers/project/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c8b5ab

Please sign in to comment.