Skip to content

Commit

Permalink
Merge branch 'main' into fix/ops/bug-issue-template
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jan 30, 2025
2 parents 818e1ef + cb8adab commit 71bdbb2
Show file tree
Hide file tree
Showing 43 changed files with 625 additions and 173 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/commitlint.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
on: push
name: Validate PR metadata

name: Commit Message
on:
pull_request:
types:
- opened
- edited
- synchronize

# NOTE: Skip check on PR so as not to confuse contributors
# NOTE: Also install a PR title checker so we don't mess up merges
jobs:
commit-msg:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
permissions:
pull-requests: read

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r cz-requirement.txt
jobs:
validate-pr:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
name: Run conventional commit checker
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check commit history
run: cz check --rev-range $(git rev-list --all --reverse | head -1)..HEAD
with:
types: |
feat
perf
fix
chore
refactor
docs
test
30 changes: 0 additions & 30 deletions .github/workflows/prtitle.yaml

This file was deleted.

1 change: 0 additions & 1 deletion cz-requirement.txt

This file was deleted.

105 changes: 88 additions & 17 deletions docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,58 @@ plugin:
This helps keep your secrets out of Ape!
Similarly, any config key-name can also be set with the same named environment variable (with a prefix).
If a configuration is left unset (i.e., not included in the `ape-config.(yaml|json|toml)` file, Ape will inspect the environment variables as a fallback, following the pattern `APE_<PLUGIN?>_SETTING`, where different plugins define different prefixes.

For example, the following config:

```yaml
contracts_folder: src/qwe
test:
number_of_accounts: 3
show_internal: True
compile:
exclude:
- "one"
- "two"
- "three"
include_dependencies: true
```

could be entirely defined with environment variables as follows:

```shell
APE_CONTRACTS_FOLDER=src/contracts
APE_TEST_NUMBER_OF_ACCOUNTS=3
APE_TEST_SHOW_INTERNAL=true
APE_COMPILE_EXCLUDE='["one", "two", "three"]'
APE_COMPILE_INCLUDE_DEPENDENCIES=true
```

Notice the `ape-compile` and `ape-test` plugin include their plugin name `APE_COMPILE` and `APE_TEST` respectively where `contracts_folder` only has the prefix `APE_` since it is not part of a plugin.

Here is the complete list of supported prefixes that come with Ape out-of-the-box:

| Module/Plugin | Prefix |
| ------------- | ------------ |
| ape | APE |
| ape_cache | APE_CACHE |
| ape_compile | APE_COMPILE |
| ape_console | APE_CONSOLE |
| ape_ethereum | APE_ETHEREUM |
| ape_networks | APE_NETWORKS |
| ape_node | APE_NODE |
| ape_test | APE_TEST |

Each plugin outside the core package may define its own prefix, but the standard is `APE_PLUGINNAME_`.

Using environment variables assists in keeping secrets out of your config files.
However, the primary config should be file-driven and environment variables should only be used when necessary.

## Base Path

Change the base path if it is different than your project root.
Change the base path if it is different from your project root.
For example, imagine a project structure like:

```
Expand Down Expand Up @@ -170,33 +219,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 +290,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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ norecursedirs = "projects"
# And 'pytest_ethereum' is not used and causes issues in some environments.
addopts = """
-p no:pytest_ethereum
-p no:boa_test
"""

python_files = "test_*.py"
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
"twine==3.8.0", # Package upload tool
],
"dev": [
# commitizen: Manage commits and publishing releases
(_HERE / "cz-requirement.txt").read_text().strip(),
"commitizen>=2.40,<2.41", # Semantic commit linting
"pre-commit", # Ensure that linters are run prior to committing
"pytest-watch", # `ptw` test watcher/runner
"ipdb", # Debugger (Must use `export PYTHONBREAKPOINT=ipdb.set_trace`)
Expand Down
5 changes: 2 additions & 3 deletions src/ape/api/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ def code(self) -> "ContractCode":
"""
The raw bytes of the smart-contract code at the address.
"""

# TODO: Explore caching this (based on `self.provider.network` and examining code)
return self.provider.get_code(self.address)
# NOTE: Chain manager handles code caching.
return self.chain_manager.get_code(self.address)

@property
def codesize(self) -> int:
Expand Down
6 changes: 3 additions & 3 deletions src/ape/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PluginConfig(BaseSettings):
a config API must register a subclass of this class.
"""

model_config = SettingsConfigDict(extra="allow")
model_config = SettingsConfigDict(extra="allow", env_prefix="APE_")

@classmethod
def from_overrides(
Expand Down Expand Up @@ -285,7 +285,7 @@ class ApeConfig(ExtraAttributesMixin, BaseSettings, ManagerAccessMixin):

def __init__(self, *args, **kwargs):
project_path = kwargs.get("project")
super(BaseSettings, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# NOTE: Cannot reference `self` at all until after super init.
self._project_path = project_path

Expand Down Expand Up @@ -350,7 +350,7 @@ def __init__(self, *args, **kwargs):
"""

# NOTE: Plugin configs are technically "extras".
model_config = SettingsConfigDict(extra="allow")
model_config = SettingsConfigDict(extra="allow", env_prefix="APE_")

@model_validator(mode="before")
@classmethod
Expand Down
11 changes: 9 additions & 2 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def custom_network(self) -> "NetworkAPI":
A :class:`~ape.api.networks.NetworkAPI` for custom networks where the
network is either not known, unspecified, or does not have an Ape plugin.
"""

ethereum_class = None
for plugin_name, ecosystem_class in self.plugin_manager.ecosystems:
if plugin_name == "ethereum":
Expand Down Expand Up @@ -1005,7 +1004,6 @@ def chain_id(self) -> int:
**NOTE**: Unless overridden, returns same as
:py:attr:`ape.api.providers.ProviderAPI.chain_id`.
"""

return self.provider.chain_id

@property
Expand Down Expand Up @@ -1131,6 +1129,13 @@ def is_adhoc(self) -> bool:
"""
return self.name == "custom" and not self._is_custom

@property
def is_custom(self) -> bool:
"""
True when this network is a configured custom network.
"""
return self._is_custom

@cached_property
def providers(self): # -> dict[str, Partial[ProviderAPI]]
"""
Expand Down Expand Up @@ -1162,6 +1167,8 @@ def providers(self): # -> dict[str, Partial[ProviderAPI]]
(self.is_fork and "Fork" in provider_class.__name__)
or (not self.is_fork and "Fork" not in provider_class.__name__)
)
and provider_class.__name__
== "Node" # Ensure uses Node class instead of GethDev
)
):
# NOTE: Lazily load provider config
Expand Down
2 changes: 1 addition & 1 deletion src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def __init__(
source_traceback: _SOURCE_TRACEBACK_ARG = None,
base_err: Optional[Exception] = None,
project: Optional["ProjectManager"] = None,
set_ape_traceback: bool = True, # Overriden default.
set_ape_traceback: bool = True, # Overridden default.
):
self.txn = txn
self.contract_address = contract_address
Expand Down
Loading

0 comments on commit 71bdbb2

Please sign in to comment.