Skip to content

Commit

Permalink
docs: document environment variable support in ape-config.yaml files (
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jun 17, 2024
1 parent 81f1fb8 commit ef5c086
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ However, here is a list of common-use cases requiring the `ape-config.yaml` file
2. Setting up project dependencies: See the [dependencies](#dependencies) section.
3. Declaring your project's plugins: See the [plugins](#plugins) section.

**Environment Variables**: `ape-config.yaml` files support environment-variable expansion.
Simply include environment variables (with the `$` prefix) in your config file and Ape will automatically expand them.

```yaml
plugin:
secret_rpc: $MY_SECRET_RPC
```
This helps keep your secrets out of Ape!
## Contracts Folder
Specify a different path to your `contracts/` directory.
Expand Down
2 changes: 1 addition & 1 deletion src/ape/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def load_config(path: Path, expand_envars=True, must_exist=False) -> dict:
and is able to be load.
Returns:
Dict (dict): Configured settings parsed from a config file.
dict: Configured settings parsed from a config file.
"""
if path.is_file():
contents = path.read_text()
Expand Down
28 changes: 28 additions & 0 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path
from typing import Optional, Union

Expand Down Expand Up @@ -39,6 +40,33 @@ def test_model_validate_path_contracts_folder():
assert cfg.contracts_folder == str(path)


def test_validate_file():
value = "pathtowherever"
with create_tempdir() as temp_dir:
file = temp_dir / "ape-config.yaml"
file.write_text(f"contracts_folder: {value}")
actual = ApeConfig.validate_file(file)

assert actual.contracts_folder == value


def test_validate_file_expands_env_vars():
secret = "mycontractssecretfolder"
env_var_name = "APE_TEST_CONFIG_SECRET_CONTRACTS_FOLDER"
os.environ[env_var_name] = secret

try:
with create_tempdir() as temp_dir:
file = temp_dir / "ape-config.yaml"
file.write_text(f"contracts_folder: ${env_var_name}")

actual = ApeConfig.validate_file(file)
assert actual.contracts_folder == secret
finally:
if env_var_name in os.environ:
del os.environ[env_var_name]


def test_deployments(networks_connected_to_tester, owner, vyper_contract_container, project):
_ = networks_connected_to_tester # Connection needs to lookup config.

Expand Down

0 comments on commit ef5c086

Please sign in to comment.