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: config can load project name from pyproject.toml project setting #2461

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
54 changes: 38 additions & 16 deletions docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,33 +170,28 @@ contract = project.MyContract.deployments[0]
Ape does not add or edit deployments in your `ape-config.yaml` file.
```

## Node
## Name

When using the `node` provider, you can customize its settings.
For example, to change the URI for an Ethereum network, do:
Configure the name of the project:

```toml
[tool.ape.node.ethereum.mainnet]
uri = "http://localhost:5030"
[tool.ape]
name = "ape-project"
```

Or the equivalent YAML:
If the name is not specified in `tool.ape` but is in `project`, Ape will use that as the project name:

```yaml
node:
ethereum:
mainnet:
uri: http://localhost:5030
```toml
[project]
name = "ape-project"
```

Now, the `ape-node` core plugin will use the URL `http://localhost:5030` to connect and make requests.
To configure this name using an `ape-config.yaml` file, do:

```{warning}
Instead of using `ape-node` to connect to an Infura or Alchemy node, use the [ape-infura](https://github.com/ApeWorX/ape-infura) or [ape-alchemy](https://github.com/ApeWorX/ape-alchemy) provider plugins instead, which have their own way of managing API keys via environment variables.
```yaml
name: ape-project
```

For more information on networking as a whole, see [this guide](./networks.html).

## Networks

Set default network and network providers:
Expand Down Expand Up @@ -246,6 +241,33 @@ ethereum:

For the local network configuration, the default is `"max"`. Otherwise, it is `"auto"`.

## Node

When using the `node` provider, you can customize its settings.
For example, to change the URI for an Ethereum network, do:

```toml
[tool.ape.node.ethereum.mainnet]
uri = "http://localhost:5030"
```

Or the equivalent YAML:

```yaml
node:
ethereum:
mainnet:
uri: http://localhost:5030
```

Now, the `ape-node` core plugin will use the URL `http://localhost:5030` to connect and make requests.

```{warning}
Instead of using `ape-node` to connect to an Infura or Alchemy node, use the [ape-infura](https://github.com/ApeWorX/ape-infura) or [ape-alchemy](https://github.com/ApeWorX/ape-alchemy) provider plugins instead, which have their own way of managing API keys via environment variables.
```

For more information on networking as a whole, see [this guide](./networks.html).

## Plugins

Set which `ape` plugins you want to always use.
Expand Down
9 changes: 8 additions & 1 deletion src/ape/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,14 @@ def load_config(path: Path, expand_envars=True, must_exist=False) -> dict:
contents = expand_environment_variables(contents)

if path.name == "pyproject.toml":
config = tomllib.loads(contents).get("tool", {}).get("ape", {})
pyproject_toml = tomllib.loads(contents)
config = pyproject_toml.get("tool", {}).get("ape", {})

# Utilize [project] for some settings.
if project_settings := pyproject_toml.get("project"):
antazoey marked this conversation as resolved.
Show resolved Hide resolved
if "name" not in config and "name" in project_settings:
config["name"] = project_settings["name"]

elif path.suffix in (".json",):
config = json.loads(contents)
elif path.suffix in (".yml", ".yaml"):
Expand Down
10 changes: 10 additions & 0 deletions tests/functional/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ def test_validate_file_shows_linenos_handles_lists():
assert "-->4" in str(err.value)


def test_validate_file_uses_project_name():
name = "apexampledapp"
with create_tempdir() as temp_dir:
file = temp_dir / "pyproject.toml"
content = f'[project]\nname = "{name}"\n'
file.write_text(content)
cfg = ApeConfig.validate_file(file)
assert cfg.name == name


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

Expand Down
Loading