Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 11, 2023
1 parent f4ebdfc commit efa6fa7
Show file tree
Hide file tree
Showing 30 changed files with 201 additions and 102 deletions.
2 changes: 1 addition & 1 deletion latest/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: f3023e2797f9cc61efdeb5e7ee9293c8
config: 2ec3a14ed9d76d18ce50b44f21cf234a
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified latest/.doctrees/commands/console.doctree
Binary file not shown.
Binary file modified latest/.doctrees/commands/networks.doctree
Binary file not shown.
Binary file modified latest/.doctrees/environment.pickle
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/ape.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/api.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/cli.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/contracts.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/exceptions.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/managers.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/plugins.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/types.doctree
Binary file not shown.
Binary file modified latest/.doctrees/methoddocs/utils.doctree
Binary file not shown.
Binary file modified latest/.doctrees/userguides/clis.doctree
Binary file not shown.
Binary file modified latest/.doctrees/userguides/networks.doctree
Binary file not shown.
Binary file modified latest/.doctrees/userguides/scripts.doctree
Binary file not shown.
58 changes: 45 additions & 13 deletions latest/_sources/userguides/clis.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,60 @@ def cli(cli_ctx):

## Network Tools

The [@network_option()](../methoddocs/cli.html#ape.cli.options.network_option) allows you to select an ecosystem / network / provider combination.
When using with the [NetworkBoundCommand](../methoddocs/cli.html#ape.cli.commands.NetworkBoundCommand) class, you can cause your CLI to connect before any of your code executes.
This is useful if your script or command requires a provider connection in order for it to run.
The [@network_option()](../methoddocs/cli.html#ape.cli.options.network_option) allows you to select an ecosystem, network, and provider.
To specify the network option, use values like:

```shell
--network ethereum
--network ethereum:sepolia
--network ethereum:mainnet:alchemy
--network ::foundry
```

To use default values automatically, omit sections of the choice, but leave the semi-colons for parsing.
For example, `::test` means use the default ecosystem and network and the `test` provider.

Use `ecosystem`, `network`, and `provider` argument names in your command implementation to access their corresponding class instances:

```python
import click
from ape import networks
from ape.cli import network_option, NetworkBoundCommand
from ape.cli import network_option

@click.command()
@network_option()
def cmd(provider):
# This command only needs the provider.
click.echo(provider.name)

@click.command()
@network_option()
def cmd(network):
# Choices like "ethereum" or "polygon:local:test".
click.echo(network)
def cmd_2(ecosystem, network, provider):
# This command uses all parts of the parsed network choice.
click.echo(ecosystem.name)
click.echo(network.name)
click.echo(provider.name)
```

The [ConnectedProviderCommand](../methoddocs/cli.html#ape.cli.commands.ConnectedProviderCommand) automatically uses the `--network` option and connects to the network before any of your code executes and then disconnects afterward.
This is useful if your script or command requires a provider connection in order for it to run.
Additionally, specify `ecosystem`, `network`, or `provider` in your command function if you need any of those instances in your `ConnectedProviderCommand`, just like when using `network_option`.

@click.command(cls=NetworkBoundCommand)
@network_option()
def cmd(network):
# Fails if we are not connected.
click.echo(networks.provider.network.name)
```python
import click
from ape.cli import ConnectedProviderCommand

@click.command(cls=ConnectedProviderCommand)
def cmd(network, provider):
click.echo(network.name)
click.echo(provider.is_connected) # True

@click.command(cls=ConnectedProviderCommand)
def cmd(provider):
click.echo(provider.is_connected) # True

@click.command(cls=ConnectedProviderCommand)
def cmd():
click.echo("Using params is from ConnectedProviderCommand is optional")
```

## Account Tools
Expand Down
6 changes: 3 additions & 3 deletions latest/_sources/userguides/networks.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ape test --network ethereum:local:foundry
ape console --network arbitrum:testnet:alchemy
```

You can also use the `--network` option on scripts that use the `main()` method approach or scripts that implement that `NetworkBoundCommand` command type.
You can also use the `--network` option on scripts that use the `main()` method approach or scripts that implement that `ConnectedProviderCommand` command type.
See [the scripting guide](./scripts.html) to learn more about scripts and how to add the network option.

**NOTE**: You can omit values to use defaults.
Expand Down Expand Up @@ -85,9 +85,9 @@ geth:
uri: https://foo.node.bar
```

## Ad-hoc Network Connection
## Custom Network Connection

If you would like to connect to a URI using the `geth` provider, you can specify a URI for the provider name in the `--network` option:
If you would like to connect to a URI using the default Ethereum node provider, you can specify a URI for the provider name in the `--network` option:

```bash
ape run script --network ethereum:mainnet:https://foo.bar
Expand Down
20 changes: 14 additions & 6 deletions latest/_sources/userguides/scripts.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,25 @@ ape run hello helloworld
```

Note that by default, `cli` scripts do not have [`ape.cli.network_option`](../methoddocs/cli.html?highlight=options#ape.cli.options.network_option) installed, giving you more flexibility in how you define your scripts.
However, you can add the `network_option` to your scripts by importing both the `NetworkBoundCommand` and the `network_option` from the `ape.cli` namespace:
However, you can add the `network_option` or `ConnectedProviderCommand` to your scripts by importing them from the `ape.cli` namespace:

```python
import click
from ape.cli import network_option, NetworkBoundCommand
from ape.cli import network_option, ConnectedProviderCommand


@click.command(cls=NetworkBoundCommand)
@network_option()
def cli(network):
click.echo(f"You are connected to network '{network}'.")
@click.command(cls=ConnectedProviderCommand)
def cli(ecosystem, network):
click(f"You selected a provider on ecosystem '{ecosystem.name}' and {network.name}.")

@click.command(cls=ConnectedProviderCommand)
def cli(network, provider):
click.echo(f"You are connected to network '{network.name}'.")
click.echo(provider.chain_id)

@click.command(cls=ConnectedProviderCommand)
def cli_2():
click.echo(f"Using any network-based argument is completely optional.")
```

Assume we saved this script as `shownet.py` and have the [ape-alchemy](https://github.com/ApeWorX/ape-alchemy) plugin installed.
Expand Down
14 changes: 0 additions & 14 deletions latest/commands/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,6 @@ <h2>console<a class="headerlink" href="#console" title="Permalink to this headin
</pre></div>
</div>
<p class="rubric">Options</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-console-network">
<span class="sig-name descname"><span class="pre">--network</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;network&gt;</span></span><a class="headerlink" href="#cmdoption-console-network" title="Permalink to this definition"></a></dt>
<dd><p>Override the default network and provider. (see <cite>ape networks list</cite> for options)</p>
<dl class="field-list simple">
<dt class="field-odd">Default<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="docutils literal notranslate"><span class="pre">&lt;function</span> <span class="pre">network_option.&lt;locals&gt;.fn</span> <span class="pre">at</span> <span class="pre">0x7efd865197e0&gt;</span></code></p>
</dd>
<dt class="field-even">Options<span class="colon">:</span></dt>
<dd class="field-even"><p>:mainnet:geth | ethereum:mainnet:geth | :mainnet | ethereum:mainnet | :goerli:geth | ethereum:goerli:geth | :goerli | ethereum:goerli | :sepolia:geth | ethereum:sepolia:geth | :sepolia | ethereum:sepolia | ::test | :local:test | ethereum::test | ethereum:local:test | ::geth | :local:geth | ethereum::geth | ethereum:local:geth | :local | ethereum:local | ethereum</p>
</dd>
</dl>
</dd></dl>

<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-console-v">
<span id="cmdoption-console-verbosity"></span><span class="sig-name descname"><span class="pre">-v</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--verbosity</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;LVL&gt;</span></span><a class="headerlink" href="#cmdoption-console-v" title="Permalink to this definition"></a></dt>
Expand Down
13 changes: 3 additions & 10 deletions latest/commands/networks.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h2>list<a class="headerlink" href="#networks-list" title="Permalink to this hea
<dd><p>Filter the results by network</p>
<dl class="field-list simple">
<dt class="field-odd">Options<span class="colon">:</span></dt>
<dd class="field-odd"><p>goerli-fork | goerli | sepolia-fork | local | mainnet-fork | sepolia | mainnet</p>
<dd class="field-odd"><p>mainnet-fork | goerli-fork | mainnet | sepolia | goerli | sepolia-fork | local</p>
</dd>
</dl>
</dd></dl>
Expand All @@ -265,7 +265,8 @@ <h2>list<a class="headerlink" href="#networks-list" title="Permalink to this hea
</section>
<section id="networks-run">
<h2>run<a class="headerlink" href="#networks-run" title="Permalink to this heading"></a></h2>
<p>Start a node process</p>
<p>partial(func, <a href="#id1"><span class="problematic" id="id2">*</span></a>args, <a href="#id3"><span class="problematic" id="id4">**</span></a>keywords) - new function with partial application
of the given arguments and keywords.</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>networks<span class="w"> </span>run<span class="w"> </span><span class="o">[</span>OPTIONS<span class="o">]</span>
</pre></div>
</div>
Expand All @@ -280,14 +281,6 @@ <h2>run<a class="headerlink" href="#networks-run" title="Permalink to this headi
<dt class="sig sig-object std" id="cmdoption-networks-run-network">
<span class="sig-name descname"><span class="pre">--network</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;network&gt;</span></span><a class="headerlink" href="#cmdoption-networks-run-network" title="Permalink to this definition"></a></dt>
<dd><p>Override the default network and provider. (see <cite>ape networks list</cite> for options)</p>
<dl class="field-list simple">
<dt class="field-odd">Default<span class="colon">:</span></dt>
<dd class="field-odd"><p><code class="docutils literal notranslate"><span class="pre">ethereum:local:geth</span></code></p>
</dd>
<dt class="field-even">Options<span class="colon">:</span></dt>
<dd class="field-even"><p>:mainnet:geth | ethereum:mainnet:geth | :mainnet | ethereum:mainnet | :goerli:geth | ethereum:goerli:geth | :goerli | ethereum:goerli | :sepolia:geth | ethereum:sepolia:geth | :sepolia | ethereum:sepolia | ::test | :local:test | ethereum::test | ethereum:local:test | ::geth | :local:geth | ethereum::geth | ethereum:local:geth | :local | ethereum:local | ethereum</p>
</dd>
</dl>
</dd></dl>

</section>
Expand Down
20 changes: 12 additions & 8 deletions latest/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ <h2 id="Symbols">Symbols</h2>
--network

<ul>
<li><a href="commands/console.html#cmdoption-console-network">console command line option</a>
</li>
<li><a href="commands/networks.html#cmdoption-networks-list-network">networks-list command line option</a>
</li>
<li><a href="commands/networks.html#cmdoption-networks-run-network">networks-run command line option</a>
Expand Down Expand Up @@ -1285,6 +1283,8 @@ <h2 id="C">C</h2>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="methoddocs/cli.html#ape.cli.commands.ConnectedProviderCommand">ConnectedProviderCommand (class in ape.cli.commands)</a>
</li>
<li><a href="methoddocs/api.html#ape.api.providers.ProviderAPI.connection_id">connection_id (ape.api.providers.ProviderAPI property)</a>

<ul>
Expand All @@ -1297,8 +1297,6 @@ <h2 id="C">C</h2>
console command line option

<ul>
<li><a href="commands/console.html#cmdoption-console-network">--network</a>
</li>
<li><a href="commands/console.html#cmdoption-console-v">--verbosity</a>
</li>
<li><a href="commands/console.html#cmdoption-console-v">-v</a>
Expand Down Expand Up @@ -1398,7 +1396,7 @@ <h2 id="C">C</h2>
</li>
<li><a href="methoddocs/plugins.html#ape.plugins.converter.ConversionPlugin.converters">converters() (ape.plugins.converter.ConversionPlugin method)</a>
</li>
<li><a href="methoddocs/managers.html#ape.managers.networks.NetworkManager.create_adhoc_geth_provider">create_adhoc_geth_provider() (ape.managers.networks.NetworkManager method)</a>
<li><a href="methoddocs/managers.html#ape.managers.networks.NetworkManager.create_custom_provider">create_custom_provider() (ape.managers.networks.NetworkManager method)</a>
</li>
<li><a href="methoddocs/api.html#ape.api.projects.ProjectAPI.create_manifest">create_manifest() (ape.api.projects.ProjectAPI method)</a>

Expand Down Expand Up @@ -1460,9 +1458,9 @@ <h2 id="D">D</h2>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="methoddocs/api.html#ape.api.networks.EcosystemAPI.default_network">default_network (ape.api.networks.EcosystemAPI property)</a>
<li><a href="methoddocs/api.html#ape.api.networks.EcosystemAPI.default_network_name">default_network_name (ape.api.networks.EcosystemAPI property)</a>
</li>
<li><a href="methoddocs/api.html#ape.api.networks.NetworkAPI.default_provider">default_provider (ape.api.networks.NetworkAPI property)</a>
<li><a href="methoddocs/api.html#ape.api.networks.NetworkAPI.default_provider_name">default_provider_name (ape.api.networks.NetworkAPI property)</a>
</li>
<li><a href="methoddocs/managers.html#ape.managers.query.DefaultQueryProvider">DefaultQueryProvider (class in ape.managers.query)</a>
</li>
Expand Down Expand Up @@ -1742,6 +1740,8 @@ <h2 id="G">G</h2>
<li><a href="methoddocs/api.html#ape.api.explorers.ExplorerAPI.get_transaction_url">get_transaction_url() (ape.api.explorers.ExplorerAPI method)</a>
</li>
<li><a href="methoddocs/api.html#ape.api.providers.ProviderAPI.get_transactions_by_block">get_transactions_by_block() (ape.api.providers.ProviderAPI method)</a>
</li>
<li><a href="methoddocs/cli.html#ape.cli.choices.get_user_selected_account">get_user_selected_account() (in module ape.cli.choices)</a>
</li>
<li><a href="methoddocs/api.html#ape.api.compiler.CompilerAPI.get_versions">get_versions() (ape.api.compiler.CompilerAPI method)</a>
</li>
Expand Down Expand Up @@ -1822,7 +1822,7 @@ <h2 id="I">I</h2>
</li>
<li><a href="methoddocs/managers.html#ape.managers.project.manager.ProjectManager.interfaces_folder">interfaces_folder (ape.managers.project.manager.ProjectManager property)</a>
</li>
<li><a href="methoddocs/cli.html#ape.cli.commands.NetworkBoundCommand.invoke">invoke() (ape.cli.commands.NetworkBoundCommand method)</a>
<li><a href="methoddocs/cli.html#ape.cli.commands.ConnectedProviderCommand.invoke">invoke() (ape.cli.commands.ConnectedProviderCommand method)</a>
</li>
<li><a href="methoddocs/contracts.html#ape.contracts.base.ContractInstance.invoke_transaction">invoke_transaction() (ape.contracts.base.ContractInstance method)</a>
</li>
Expand Down Expand Up @@ -2329,6 +2329,8 @@ <h2 id="N">N</h2>
<li><a href="methoddocs/exceptions.html#ape.exceptions.NetworkMismatchError">NetworkMismatchError</a>
</li>
<li><a href="methoddocs/exceptions.html#ape.exceptions.NetworkNotFoundError">NetworkNotFoundError</a>
</li>
<li><a href="methoddocs/cli.html#ape.cli.options.NetworkOption">NetworkOption (class in ape.cli.options)</a>
</li>
<li><a href="methoddocs/plugins.html#ape.plugins.network.NetworkPlugin">NetworkPlugin (class in ape.plugins.network)</a>
</li>
Expand Down Expand Up @@ -2413,6 +2415,8 @@ <h2 id="P">P</h2>
<li><a href="commands/pm.html#cmdoption-pm-remove-arg-PACKAGE">pm-remove command line option</a>
</li>
</ul></li>
<li><a href="methoddocs/cli.html#ape.cli.commands.ConnectedProviderCommand.parse_args">parse_args() (ape.cli.commands.ConnectedProviderCommand method)</a>
</li>
<li><a href="methoddocs/managers.html#ape.managers.networks.NetworkManager.parse_network_choice">parse_network_choice() (ape.managers.networks.NetworkManager method)</a>
</li>
<li><a href="methoddocs/api.html#ape.api.projects.ProjectAPI.path">path (ape.api.projects.ProjectAPI attribute)</a>
Expand Down
Loading

0 comments on commit efa6fa7

Please sign in to comment.