-
Notifications
You must be signed in to change notification settings - Fork 76
Replace subprocess #236
Replace subprocess #236
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
logging.info(output) | ||
|
||
return output | ||
return output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not logging on query anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still logging on query, the log command is before the query_flag
and watch_mode
conditional. The logic is just consolidated from how it was:
if type != "call" and output:
logging.info(output)
if not query_flag and watch_mode:
transaction_hash = _get_transaction_hash(output)
return await status(normalize_number(transaction_hash), network, watch_mode)
src/nile/core/declare.py
Outdated
contract_name=contract_name, | ||
signature=signature, | ||
signature=prepare_params(signature), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can/should prepare_params
be called within execute_call
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can and they were. The idea was to support set_command_args
using a loop for most of the args (meaning less if
statements and verbosity). That said, they probably should be called in execute_call
. I'll throw them back in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see prepare_params
is used for signature inside execute_call
already but hasn't been removed here right?
tests/commands/test_get_nonce.py
Outdated
# args = set_args("goerli") | ||
command_args = {"contract_address": "0x4d2"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# args = set_args("goerli") | |
command_args = {"contract_address": "0x4d2"} | |
command_args = {"contract_address": contract_address} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test checks that non-0x addresses convert to hex (hence the hardcoded 0x4d2
)
src/nile/starknet_cli.py
Outdated
|
||
|
||
def _add_args(key, value): | ||
return [f"--{key}", *value] if type(value) is list else [f"--{key}", value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return [f"--{key}", *value] if type(value) is list else [f"--{key}", value] | |
return [f"--{key}", *value] if type(value) is list else [f"--{key}", value] |
is it enough with *value
or should we flatten if there's nested lists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, flattening seems correct
Co-authored-by: Martín Triay <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good Andrew! I left a couple of comments.
@@ -2,7 +2,7 @@ | |||
"""Nile CLI entry point.""" | |||
import logging | |||
|
|||
import click | |||
import asyncclick as click |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/nile/core/declare.py
Outdated
contract_name=contract_name, | ||
signature=signature, | ||
signature=prepare_params(signature), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see prepare_params
is used for signature inside execute_call
already but hasn't been removed here right?
src/nile/core/deploy.py
Outdated
contract_name=contract_name, | ||
inputs=prepare_params(arguments), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we calling prepare_params
for inputs inside execute_call
already?
Co-authored-by: Eric Nordelo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good Andrew!
Co-authored-by: Eric Nordelo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 🚀 🚀 🚀 🚀 🚀
This PR supersedes #169 and resolves #161.
This PR proposes to include some notable changes that enable the removal of
subprocess
.Account
Account
class requiresAccount
to inherit theAsyncObject
class.__init__
s; therefore, this is a bit of a hacky workaround.Account
initialization and deployment.starknet_cli
starknet_cli
calls accept two parameters:args
andcommand_args
.args
: a dictionary wrapped inSimpleNamespace
.command_args
: commands passed in an array as strings (similar to how Nile passed arguments tosubprocess
).set_args
function just requires the network and returns the necessary object to pass tostarknet_cli
.command_args
are appropriately created in the function itself.capture_stdout
captures the print statements from thestarknet_cli
calls. This is because those function calls do not return the values.CLI
asyncclick
.NRE
async
/await
.async def run(nre):
balance = await nre.call(...)
Testing
async
/await
when testing async functions.AsyncMock
should be used.