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

feat: properly support project-level settings #2316

Merged
merged 7 commits into from
Oct 15, 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
40 changes: 39 additions & 1 deletion docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ There are two locations you can place an `ape-config.yaml` file.

Project settings take precedent, but global settings allow you to configure preferences across all projects, such as your default mainnet provider (e.g. Alchemy versus running your own node).

This guide serves as an index of the settings you can include in any `ape-config.yaml` file.
This guide serves as an index of some settings you can include in any `ape-config.yaml` file.
This guide is **PURPOSELY** alphabetized to facilitate easier look-up of keys.
Plugins for Ape may define their own configs.

Most of the features in this guide are documented more-fully elsewhere in the user-guides.

Expand Down Expand Up @@ -242,3 +243,40 @@ test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 5
```
## Plugin Settings
To configure a plugin, use the name of the plugin followed by any of the plugin's settings.
For example, to configure the `ape-solidity` plugin, you would do:

```yaml
solidity:
evm_version: paris # Or any other setting defined in `ape-solidity`.
```

## Non-plugin settings

Projects can use their own settings.
Meaning, you can put whatever data you want in an `ape-config.yaml` file and read it in Ape.

```{note}
These types of settings lack sophisticated Pydantic validation and are limited in that respect.
Simple validation, however, will occur, such as if it the value `isnumeric()`, it will be converted to an int, or if the value is a boolean name it will convert it to a `bool`.
```

```yaml
my_project_key:
my_string: "my_value"
my_int: 123
my_bool: True
```
Then, to access it (or any setting for that matter):
```python
from ape import project

my_str = project.config.my_project_key.my_string # "my_value"
my_int = project.config.my_project_key.my_int # 123
my_bool = project.config.my_project_key.my_bool # True
```
13 changes: 13 additions & 0 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,16 @@ def test_dependencies_list_of_non_dicts(project):
expected = "Expecting mapping for dependency. Received: int."
with pytest.raises(ConfigError, match=expected):
_ = ApeConfig.model_validate(data)


def test_project_level_settings(project):
"""
Settings can be configured in an ape-config.yaml file
that are not part of any plugin. This test ensures that
works.
"""
# NOTE: Using strings for the values to show simple validation occurs.
with project.temp_config(my_string="my_string", my_int=123, my_bool=True):
assert project.config.my_string == "my_string"
assert project.config.my_int == 123
assert project.config.my_bool is True
2 changes: 1 addition & 1 deletion tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def clean():
):
actual = pm.sources.lookup(closest)
expected = nested_source_a
assert actual == expected, f"Failed to lookup {closest}"
assert actual.stem == expected.stem, f"Failed to lookup {closest}"

# Nested: 2nd level
for closest in (
Expand Down
Loading