Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Replace subprocess #236

Merged
merged 92 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
3b9bd03
add async deps
andrew-fleming Oct 17, 2022
31faeb4
update funcs to async
andrew-fleming Oct 17, 2022
4313220
adjust run_cmd, add helper funcs
andrew-fleming Oct 17, 2022
4ee68d4
adjust methods to async
andrew-fleming Oct 17, 2022
3c916bb
adjust nre to async
andrew-fleming Oct 17, 2022
6d742af
fix formatting
andrew-fleming Oct 17, 2022
c47a75a
replace arg object, fix nre and output
andrew-fleming Oct 17, 2022
1fe7e8d
fix formatting
andrew-fleming Oct 17, 2022
0f5770f
add rstrip to capture
andrew-fleming Oct 18, 2022
2c38d82
async get-nonce
andrew-fleming Oct 18, 2022
485469f
remove comments
andrew-fleming Oct 18, 2022
f7c76c7
fix formatting
andrew-fleming Oct 18, 2022
2c205e8
add event loop
andrew-fleming Oct 18, 2022
cf3896e
update tests without subprocess
andrew-fleming Oct 19, 2022
26cf600
update cli tests with asyncclick
andrew-fleming Oct 19, 2022
515a1fa
adjust tests to async
andrew-fleming Oct 19, 2022
054cce6
add set_args func
andrew-fleming Oct 19, 2022
0b0da87
simplify context with set_args
andrew-fleming Oct 19, 2022
602b14b
remove subprocess, add set_args
andrew-fleming Oct 19, 2022
195a24b
add tests for common funcs
andrew-fleming Oct 20, 2022
9fe9d17
async debug, remove subprocess
andrew-fleming Oct 20, 2022
50484e8
fix test
andrew-fleming Oct 21, 2022
9064a8c
fix conflicts
andrew-fleming Oct 28, 2022
f6c7933
fix conflicts
andrew-fleming Oct 28, 2022
e0f066c
fix account test conflicts
andrew-fleming Oct 28, 2022
4170096
update account tests to async
andrew-fleming Oct 31, 2022
cb138a7
update debug test to async
andrew-fleming Oct 31, 2022
552b42c
update get_accounts to async
andrew-fleming Oct 31, 2022
910490e
start test refactor
andrew-fleming Oct 31, 2022
4e36c40
fix conflicts
andrew-fleming Nov 2, 2022
8c4e3f2
add async to nre snippets
andrew-fleming Nov 2, 2022
87621b2
add language to code block
andrew-fleming Nov 2, 2022
d04f45d
fix conflicts
andrew-fleming Nov 2, 2022
ce76753
fix url tests
andrew-fleming Nov 2, 2022
ec61c35
fix tests
andrew-fleming Nov 2, 2022
122a481
fix formatting
andrew-fleming Nov 2, 2022
f0a2a62
fix get_gateway handling
andrew-fleming Nov 2, 2022
c8f92e1
remove redundant mock
andrew-fleming Nov 2, 2022
bf49f3f
fix formatting
andrew-fleming Nov 2, 2022
0f5a7c8
remove unused func
andrew-fleming Nov 2, 2022
1333b42
fix conflicts
andrew-fleming Nov 3, 2022
4085231
Merge branch 'main' into replace-subprocess
andrew-fleming Nov 3, 2022
8075a2d
clean up test
andrew-fleming Nov 3, 2022
7058547
fix network handling
andrew-fleming Nov 3, 2022
f673b26
fix tx_status calls
andrew-fleming Nov 3, 2022
154ff15
fix conflicts
andrew-fleming Nov 4, 2022
57395fa
add call_cli func
andrew-fleming Nov 5, 2022
13a5a36
abstract command args
andrew-fleming Nov 5, 2022
d7c0577
fix tests with call_cli
andrew-fleming Nov 5, 2022
c6e4eae
fix tests with call_cli
andrew-fleming Nov 5, 2022
a8209b7
fix formatting
andrew-fleming Nov 5, 2022
5ccf195
fix conflicts
andrew-fleming Nov 7, 2022
ae62502
remove unnecessary hex
andrew-fleming Nov 9, 2022
67f8f0b
remove async from simulate methods
andrew-fleming Nov 10, 2022
f57df83
remove unnecessary int conversion
andrew-fleming Nov 10, 2022
8a5bac0
add comment regarding AsyncObject in Account
andrew-fleming Nov 10, 2022
b7f2dd8
handle async logging
andrew-fleming Nov 10, 2022
ab02531
fix formatting
andrew-fleming Nov 10, 2022
33f4ad0
refactor _process_arguments
andrew-fleming Nov 10, 2022
d674b53
fix formatting
andrew-fleming Nov 10, 2022
effe69b
fix conflicts
andrew-fleming Nov 12, 2022
7fa5ac7
fix _process_arguments
andrew-fleming Nov 12, 2022
6df837f
fix test
andrew-fleming Nov 13, 2022
73de60a
fix tx output and error handling
andrew-fleming Nov 14, 2022
86e7851
fix formatting
andrew-fleming Nov 14, 2022
ede0077
add starknet_cli module
andrew-fleming Nov 14, 2022
97bc116
improve command_args handling
andrew-fleming Nov 14, 2022
0bbb764
fix sender param
andrew-fleming Nov 14, 2022
b808dfb
fix docstring formatting
andrew-fleming Nov 14, 2022
cc58510
add starknet_cli tests
andrew-fleming Nov 14, 2022
303d634
fix status test
andrew-fleming Nov 14, 2022
517a564
move tests to starknet_cli
andrew-fleming Nov 14, 2022
42cca30
update patch location
andrew-fleming Nov 14, 2022
483cd3a
test args in execute_call
andrew-fleming Nov 15, 2022
f33ccc2
add comments
andrew-fleming Nov 15, 2022
fbcef31
remove comments
andrew-fleming Nov 15, 2022
4952346
Apply suggestions from code review
andrew-fleming Nov 15, 2022
aba30ec
remove comment
andrew-fleming Nov 15, 2022
88eb64b
rename set_args to set_context
andrew-fleming Nov 15, 2022
6b126b7
reorder _process_arguments params
andrew-fleming Nov 15, 2022
cdc7cbc
support nested lists in _add_args
andrew-fleming Nov 15, 2022
17b6e91
suppress pytest warning
andrew-fleming Nov 15, 2022
313cd6c
fix test
andrew-fleming Nov 15, 2022
966ae14
call prepare_params in starknet_cli
andrew-fleming Nov 15, 2022
d44f78f
fix tests
andrew-fleming Nov 15, 2022
3ded033
Update src/nile/core/declare.py
andrew-fleming Nov 15, 2022
02381be
remove prepare_params from deploy and declare
andrew-fleming Nov 15, 2022
df1e71f
fix formatting
andrew-fleming Nov 15, 2022
fab1279
fix tests
andrew-fleming Nov 15, 2022
ee0a44a
Update tests/test_starknet_cli.py
andrew-fleming Nov 15, 2022
f27558e
Update src/nile/core/declare.py
martriay Nov 16, 2022
d37ce19
convert max_fee to str in starknet_cli
andrew-fleming Nov 17, 2022
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
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ Please note:

### `run`

Execute a script in the context of Nile. The script must implement a `run(nre)` function to receive a `NileRuntimeEnvironment` object exposing Nile's scripting API.
Execute a script in the context of Nile. The script must implement an asynchronous `run(nre)` function to receive a `NileRuntimeEnvironment` object exposing Nile's scripting API.

```python
# path/to/script.py

def run(nre):
address, abi = nre.deploy("contract", alias="my_contract")
async def run(nre):
address, abi = await nre.deploy("contract", alias="my_contract")
print(abi, address)
```

Expand Down Expand Up @@ -368,7 +368,7 @@ Retrieves a list of ready-to-use accounts which allows for easy scripting integr

1. store private keys in a `.env`

```
```txt
PRIVATE_KEY_ALIAS_1=286426666527820764590699050992975838532
PRIVATE_KEY_ALIAS_2=263637040172279991633704324379452721903
PRIVATE_KEY_ALIAS_3=325047780196174231475632140485641889884
Expand All @@ -388,18 +388,18 @@ Retrieves a list of ready-to-use accounts which allows for easy scripting integr
Next, write a script and call `get-accounts` to retrieve and use the deployed accounts.

```python
def run(nre):
async def run(nre):

# fetch the list of deployed accounts
accounts = nre.get_accounts()
accounts = await nre.get_accounts()

# then
accounts[0].send(...)
await accounts[0].send(...)

# or
alice, bob, *_ = accounts
alice.send(...)
bob.send(...)
await alice.send(...)
await bob.send(...)
```

> Please note that the list of accounts includes only those that exist in the local `<network>.accounts.json` file. In a recent release we added a flag to the command, to get predeployed accounts if the network you are connected to is a [starknet-devnet](https://github.com/Shard-Labs/starknet-devnet) instance.
Expand All @@ -417,18 +417,18 @@ nile get-accounts --predeployed
Or from the nile runtime environment for scripting:

```python
def run(nre):
async def run(nre):

# fetch the list of pre-deployed accounts from devnet
accounts = nre.get_accounts(predeployed=True)
accounts = await nre.get_accounts(predeployed=True)

# then
accounts[0].send(...)
await accounts[0].send(...)

# or
alice, bob, *_ = accounts
alice.send(...)
bob.send(...)
await alice.send(...)
await bob.send(...)
```

### `get-nonce`
Expand All @@ -444,8 +444,8 @@ nile get-nonce <contract_address>
Return the hash of a declared class. This can be useful in scenarios where a contract class is already declared with an alias prior to running a script.

```python
def run(nre):
predeclared_class = nre.get_declaration("alias")
async def run(nre):
predeclared_class = await nre.get_declaration("alias")
```

> Note that this command is only available in the context of scripting in the Nile Runtime Environment.
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ package_dir =
python_requires = >=3.8,<3.10

install_requires =
anyio>=3.6.1
asyncclick>=8.1.3.4
click>=8.0,<9.0
importlib-metadata>=4.0
python-dotenv>=0.19.2
Expand Down
68 changes: 33 additions & 35 deletions src/nile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Nile CLI entry point."""
import logging

import click
import asyncclick as click
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is asyncclick usage implying a requirement to update plugins accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! I'm honestly not sure. I'll try and test it to find out


from nile.common import is_alias
from nile.core.account import Account
Expand All @@ -25,6 +25,7 @@
from nile.utils.status import status as status_command

logging.basicConfig(level=logging.DEBUG, format="%(message)s")
logging.getLogger("asyncio").setLevel(logging.WARNING)

NETWORKS = ("localhost", "integration", "goerli", "goerli2", "mainnet")

Expand Down Expand Up @@ -85,9 +86,9 @@ def init():
@cli.command()
@click.argument("path", nargs=1)
@network_option
def run(path, network):
async def run(path, network):
"""Run Nile scripts with NileRuntimeEnvironment."""
run_command(path, network)
await run_command(path, network)


@cli.command()
Expand All @@ -98,13 +99,13 @@ def run(path, network):
@network_option
@mainnet_token_option
@watch_option
def deploy(artifact, arguments, network, alias, watch_mode, abi, token):
async def deploy(artifact, arguments, network, alias, abi, token, watch_mode):
"""Deploy StarkNet smart contract."""
deploy_command(
contract_name=artifact,
arguments=arguments,
network=network,
alias=alias,
await deploy_command(
artifact,
arguments,
network,
alias,
abi=abi,
mainnet_token=token,
watch_mode=watch_mode,
Expand All @@ -120,7 +121,7 @@ def deploy(artifact, arguments, network, alias, watch_mode, abi, token):
@network_option
@mainnet_token_option
@watch_option
def declare(
async def declare(
signer,
contract_name,
network,
Expand All @@ -131,8 +132,8 @@ def declare(
token,
):
"""Declare StarkNet smart contract."""
account = Account(signer, network)
account.declare(
account = await Account(signer, network)
await account.declare(
contract_name,
alias=alias,
max_fee=max_fee,
Expand All @@ -146,9 +147,9 @@ def declare(
@click.argument("signer", nargs=1)
@network_option
@watch_option
def setup(signer, network, watch_mode):
async def setup(signer, network, watch_mode):
"""Set up an Account contract."""
Account(signer, network, watch_mode=watch_mode)
await Account(signer, network, watch_mode=watch_mode)


@cli.command()
Expand All @@ -161,7 +162,7 @@ def setup(signer, network, watch_mode):
@click.option("--estimate_fee", "query", flag_value="estimate_fee")
@network_option
@watch_option
def send(
async def send(
signer,
address_or_alias,
method,
Expand All @@ -172,15 +173,15 @@ def send(
watch_mode,
):
"""Invoke a contract's method through an Account."""
account = Account(signer, network)
account = await Account(signer, network)
print(
"Calling {} on {} with params: {}".format(
method, address_or_alias, [x for x in params]
)
)
# address_or_alias is not normalized first here because
# Account.send is part of Nile's public API and can accept hex addresses
account.send(
await account.send(
address_or_alias,
method,
params,
Expand All @@ -195,18 +196,15 @@ def send(
@click.argument("method", nargs=1)
@click.argument("params", nargs=-1)
@network_option
def call(address_or_alias, method, params, network):
async def call(address_or_alias, method, params, network):
"""Call functions of StarkNet smart contracts."""
if not is_alias(address_or_alias):
address_or_alias = normalize_number(address_or_alias)
out = call_or_invoke_command(
contract=address_or_alias,
type="call",
method=method,
params=params,
network=network,
out = await call_or_invoke_command(
address_or_alias, "call", method, params, network
)
print(out)
logging.info(out)
return out


@cli.command()
Expand Down Expand Up @@ -293,21 +291,21 @@ def version():
@click.argument("tx_hash", nargs=1)
@click.option("--contracts_file", nargs=1)
@network_option
def debug(tx_hash, network, contracts_file):
async def debug(tx_hash, network, contracts_file):
"""
Locate an error in a transaction using available contracts.

Alias for `nile status --debug`.
"""
status_command(normalize_number(tx_hash), network, "debug", contracts_file)
await status_command(normalize_number(tx_hash), network, "debug", contracts_file)


@cli.command()
@click.argument("tx_hash", nargs=1)
@click.option("--contracts_file", nargs=1)
@network_option
@watch_option
def status(tx_hash, network, watch_mode, contracts_file):
async def status(tx_hash, network, watch_mode, contracts_file):
"""
Get the status of a transaction.

Expand All @@ -320,7 +318,7 @@ def status(tx_hash, network, watch_mode, contracts_file):
$ nile status --debug transaction_hash
Same as `status --track` then locate errors if rejected using local artifacts
"""
status_command(
await status_command(
normalize_number(tx_hash),
network,
watch_mode=watch_mode,
Expand All @@ -331,24 +329,24 @@ def status(tx_hash, network, watch_mode, contracts_file):
@cli.command()
@click.option("--predeployed/--registered", default=False)
@network_option
def get_accounts(network, predeployed):
async def get_accounts(network, predeployed):
"""Retrieve and manage deployed accounts."""
if not predeployed:
return get_accounts_command(network)
return await get_accounts_command(network)
else:
return get_predeployed_accounts_command(network)
return await get_predeployed_accounts_command(network)


@cli.command()
@click.argument("contract_address")
@network_option
def get_nonce(contract_address, network):
async def get_nonce(contract_address, network):
"""Retrieve the nonce for a contract."""
return get_nonce_command(normalize_number(contract_address), network)
return await get_nonce_command(normalize_number(contract_address), network)


cli = load_plugins(cli)


if __name__ == "__main__":
cli()
cli(_anyion_backend="asyncio")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this results in this being logged every time:

Using selector: EpollSelector

image

try disabling the logging

Loading