Skip to content

Commit

Permalink
fix: issue where plugin config loading error was not shown (#2150)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jun 17, 2024
1 parent 82bd563 commit 5e5649a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/ape/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]:
"""
Expand Down
5 changes: 5 additions & 0 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5e5649a

Please sign in to comment.