Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue where plugin config loading error was not shown #2150

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug was fixed by deleting this method.
get_config still exists on ApeConfig class, and thus is still available here, only without swallowing every single error

"""
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
Loading