From 5e5649a9e953b28fe7aa0ca20641bb40c9737faa Mon Sep 17 00:00:00 2001 From: antazoey Date: Mon, 17 Jun 2024 16:56:29 -0500 Subject: [PATCH] fix: issue where plugin config loading error was not shown (#2150) --- src/ape/managers/config.py | 18 ------------------ src/ape_ethereum/ecosystem.py | 5 +++++ tests/functional/test_config.py | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/ape/managers/config.py b/src/ape/managers/config.py index 60aa8672a2..ce63dbe1b7 100644 --- a/src/ape/managers/config.py +++ b/src/ape/managers/config.py @@ -7,7 +7,6 @@ from ethpm_types import PackageManifest -from ape.api import PluginConfig from ape.api.config import ApeConfig from ape.managers.base import BaseManager from ape.utils import create_tempdir, in_tempdir, log_instead_of_fail @@ -67,7 +66,6 @@ def __getattr__(self, name: str) -> Any: See :class:`~ape.api.config.ApeConfig` for field definitions and model-related controls. """ - return get_attribute_with_extras(self, name) def __getitem__(self, name: str) -> Any: @@ -106,22 +104,6 @@ def extract_config(cls, manifest: PackageManifest, **overrides) -> ApeConfig: """ return ApeConfig.from_manifest(manifest, **overrides) - def get_config(self, plugin_name: str) -> PluginConfig: - """ - Get the config for a plugin. - - Args: - plugin_name (str): The name of the plugin. - - Returns: - :class:`~ape.api.config.PluginConfig` - """ - try: - return self.__getattr__(plugin_name) - except AttributeError: - # Empty config. - return PluginConfig() - @contextmanager def isolate_data_folder(self) -> Iterator[Path]: """ diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index 1b57bdccba..5a7671bd0a 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -87,6 +87,11 @@ class NetworkConfig(PluginConfig): + """ + The Ethereum network config base class for each + network, e.g. ``"mainnet"``, ```"local"``, etc. + """ + required_confirmations: int = 0 """ The amount of blocks to wait before diff --git a/tests/functional/test_config.py b/tests/functional/test_config.py index 2e52d95c33..5f991a26ec 100644 --- a/tests/functional/test_config.py +++ b/tests/functional/test_config.py @@ -3,6 +3,7 @@ from typing import Optional, Union import pytest +from pydantic import ValidationError from pydantic_settings import SettingsConfigDict from ape.api.config import ApeConfig, ConfigEnum, PluginConfig @@ -377,6 +378,28 @@ def hacked_in_method(): config.local_project.config._get_config_plugin_classes = original_method +def test_get_config_unknown_plugin(config): + """ + Simulating reading plugin configs w/o those plugins installed. + """ + actual = config.get_config("thisshouldnotbeinstalled") + assert isinstance(actual, PluginConfig) + + +def test_get_config_invalid_plugin_config(project): + with project.temp_config(node={"ethereum": [1, 2]}): + # Show project's ApeConfig model works. + with pytest.raises(ValidationError): + project.config.get_config("node") + + # Show the manager-wrapper also works + # (simple wrapper for local project's config, + # but at one time pointlessly overrode the `get_config()` + # which caused issues). + with pytest.raises(ValidationError): + project.config_manager.get_config("node") + + def test_write_to_disk_json(config): with create_tempdir() as base_path: path = base_path / "config.json"